Guide to Opening/Closing Ports on VPS (Linux& Windows)
While using a VPS, opening and closing ports is a necessary task for services to function and be accessed from the outside. However, if misconfigured, you might encounter...
While using a VPS, you may need toopen portso that websites, SSH, Remote Desktop, databases, APIs, or other applications can receive incoming connections.
Conversely, ports that are no longer in use should becloseto limit unnecessary connections and increase security for the VPS.
In this article, VPTS will provide detailed instructions on how toopen, close, and check ports on Linux and Windows VPS, applicable to popular operating systems such as Ubuntu, Debian, AlmaLinux, Rocky Linux, CentOS, and Windows Server.
1. What Is a Port on a VPS?
A port can simply be understood as a network communication endpoint used by services on a VPS to receive or send connections.
A single IP address can use multiple different ports. Each application typically listens on one or several specific ports.
2. Common Ports You Need to Know
| Services | Port |
|---|---|
| SSH (Linux) | 22 |
| HTTP (Website) | 80 |
| HTTPS | 443 |
| FTP | 21 |
| Remote Desktop – RDP | 3389 |
| MySQL/MariaDB | 3306 |
| PostgreSQL | 5432 |
Note:These are only default ports. Administrators can completely change the port of each service to another number.
3. Guide to opening/closing ports on Linux VPS
3.1. For Ubuntu (UFW)
Step 1: Check UFW status
sudo ufw status
- Returned result -> active->UFW is active.
- Open a single port (Allow): for example, open port 80
- The result will return as shown in the image below

Quick note: Command to open port 80 over TCP protocol. Replace80with the port number you need. (If the firewall is disabled, the port opening rules will not take effect
Step 2: Open a port
- Example: need to open port
80:
sudo ufw allow 80/tcp- If successful, UFW will add a rule allowing TCP connections to port 80.
- You just need to replace
80with the required port.
Step 3: Open HTTPS port 443
sudo ufw allow 80,443/tcp- Delete opened rule
sudo ufw delete allow 80The result will return as shown in the image below

Step 5: Check ports currently allowed by UFW
Run:
sudo ufw status numberedThe result will return as shown in the image below

- If you want to delete by index number, run a command similar to the following
sudo ufw delete 5No. are series of numbers 1, 2, 3, 4, 5, 6 as you see

3.2. For FirewallD (CentOS 7+, RHEL, AlmaLinux)
Operating systems in the RHEL family typically usefirewalldto manage the firewall.
Step 1: Check FirewallD
Run:
sudo systemctl status firewalldStep 2: Start FirewallD if it is not running
Run:
systemctl start firewalld
systemctl enable firewalld- Then verify:
sudo systemctl status firewalld- Returned result active (running) ->ok

Step 3: Open a port
Example: opening TCP port8080:
sudo firewall-cmd --add-port=8080/tcp --permanent
sudo firewall-cmd --reloadIf the result shows success, it is successful

Step 4: Open ports 80 and 443
- Run:
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=443/tcp
firewall-cmd --reloadAll succeeded, linewarning: ALREADY_ENABLED: 80:tcp is not an error; it means that port 80 was already open beforehand.

Step 5: Check list of opened ports
Run:
sudo firewall-cmd --list-portsDisplays all opened ports

3.3. Open port with IPTables
Some legacy VPSs or Linux systems still manage firewalls directly using IPTables.
- Example: opening TCP port
8080:
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT- Check open ports
iptables -L -nDisplays all ports as shown in the image

4. Guide to opening/closing ports on Windows VPS
4.1. Open port using Windows Firewall (popular method)
Step 1: Open firewall
- Click search and typeWindows Defender Firewall with Advanced Security. Select Inbound Rules -> New Rule.

Step 2: Select rule type
- Select port and click Next

- Select TCP or UDP, enter the port to open

Step 3: Allow connection
- Select Allow the connection and click Next -> Next

- Name and finish

Related articles to refer to below
4.2. Open port using CMD
- Open port 80
netsh advfirewall firewall add rule name="Open Port 80" dir=in action=allow protocol=TCP localport=80- Open port 443
netsh advfirewall firewall add rule name="Open Port 443" dir=in action=allow protocol=TCP localport=443- Open Remote Desktop port (3389)
netsh advfirewall firewall add rule name="RDP Port 3389" dir=in action=allow protocol=TCP localport=33894.3. Disable (close) port on Windows
Method 1: Disable via GUI
- Go toInbound Rules
- Find the created rule
- Right-click →DisableorDelete

Method 2: Delete via CMD
sudo ufw allow 80netsh advfirewall firewall delete rule name="Open Port 80"5. Why can't I connect even though the VPS port has been opened?
- Cloud firewall not yet opened
- Application not running (not listening on port)
- Firewall not enabled or misconfigured
- Wrong port or wrong protocol
- Incorrect domain or IP
At VPTS, we not only provide VPS but also support customers with:
- Standard security firewall configuration
- Open the correct port for each service (Web, Docker, AI, N8N…)
- Performance optimization and quick troubleshooting
CONCLUSION
Through the company's guideVPTSopening and closing ports on a VPS (Linux&Windows) is an important step to ensure the system operates stably and securely. Just properly configure the firewall, open the necessary ports, and ensure the application is active to easily control access and optimize VPS performance effectively.
VPTS – Comprehensive Digital Infrastructure Solutions Provider
VPTS is a digital infrastructure solution provider in Vietnam, serving deployment, operation, and data storage needs for individuals, developers, and enterprises. The service ecosystem includesVietnam VPS, International VPS, VPS Anti DDoS, Hosting cPanel, dedicated server, Rack rental, Proxy IPv4/IPv6, S3 MinIOandCloud Storage.
Besides providing infrastructure resources, VPTS also focuses on assisting customers with deployment, configuration, and practical troubleshooting. Content on the VPTS Blog is drawn from common scenarios in operating VPS, servers, and online systems, helping readers understand root causes and apply clear solutions.
VPTS – Stable infrastructure, flexible solutions, and continuous partnership throughout operations.
VPTS Team Contact Information
Website: https://vpts.shop
Facebook: https://www.facebook.com/trang.vpsttt/
Zalo OA: https://zalo.me/vpstttgroup
Hotline: 0328 812 674