🔥 Open a port on Windows 11
🎯 Learning Objective
- Know how to open/close a port on Windows 11
📜 Statement
As part of your work as a developer, it may be necessary to open a port on your computer to allow an application to communicate with other machines on the network. For example, if you are setting up a web server, you will need to open port 80 so that users can access your site.
In this exercise, we will open port 80 to allow a web server to run on your computer. Port 80 is the default port for the HTTP protocol. In a production environment, it is recommended to use port 443 for the HTTPS protocol, which is secure.
Step 1: Configure your VM in bridge mode
- Ensure that your VM is configured in bridge mode. This will allow your VM to have an IP address on the same network as your host computer. On VirtualBox, you can do this by going to your VM's settings, then to the "Network" tab.
Step 2: Start a web server on your VM
- Install Python on your VM if it is not already installed.
- Create a
webdirectory on your VM in your user directory. - Create an
index.htmlfile in this directory with the following content:
<!DOCTYPE html>
<html>
<head>
<title>Hello</title>
</head>
<body>
Hello World
</body>
</html>
- Open PowerShell and execute the following command to start a web server on port 80:
py -m http.server 80 --directory C:\Users\<your_username>\web
Step 3: Test from your host machine
Normally, port 80 is closed by default on Windows 11. You will not be able to access your web server from your host machine. To verify, open a web browser and enter your VM's IP address in the address bar.
To find your VM's IP address, open a command prompt and execute the following command:
ipconfig
Step 4: Open port 80 on Windows 11
- Open port 80 using the Windows firewall.
Step 5: Test again from your host machine
- Open a web browser and enter your VM's IP address in the address bar. You should see the message "Hello World" displayed.
Step 6: Close port 80 on Windows 11
- Close port 80 using the Windows firewall.
- Test again from your host machine. You should no longer see the message "Hello World" displayed.
Step 7: Close the web server
- Close the web server by pressing
Ctrl + Cin the PowerShell window where you started it. - Close the PowerShell window.
Congratulations! You have successfully opened and closed a port on Windows 11 and maybe even created your first web server!