Table of Contents
UFW (Uncomplicated Firewall) allows Ubuntu administrators to manage firewall rules using simple commands. Opening specific ports is necessary for services such as websites, SSH access, databases, and game servers.
On a public Linux VPS server, correctly configuring firewall ports helps keep services accessible while reducing unnecessary exposure to the internet.
Step 1: Connect to the Ubuntu Server
Access the server using SSH:
ssh root@your_server_ip
Step 2: Check UFW Status
Verify that the firewall is installed and active:
ufw status verbose
If UFW is not installed yet, follow this guide to install UFW Firewall on Ubuntu before continuing.
Step 3: Open a Specific Port
Allow incoming traffic on port 80:
ufw allow 80/tcp
Example for HTTPS traffic:
ufw allow 443/tcp
The tcp protocol is commonly used for web servers, SSH, and application services.
Step 4: Open a UDP Port
Some applications use UDP instead of TCP.
Example:
ufw allow 53/udp
UDP is commonly used for DNS, voice services, and game servers.
Step 5: Open a Port Range
Allow multiple ports at once:
ufw allow 6000:6010/tcp
This is useful for applications requiring several ports simultaneously.
Step 6: Allow SSH Access
Ensure SSH connections remain accessible:
ufw allow OpenSSH
Or allow a custom SSH port:
ufw allow 2222/tcp
Incorrect SSH firewall rules can lock administrators out of the VPS server.
Step 7: Reload UFW Rules
Reload the firewall configuration:
ufw reload
Check the updated firewall rules:
ufw status numbered
Step 8: Remove an Open Port Rule
Delete a firewall rule by port:
ufw delete allow 80/tcp
You can also remove rules using their rule number:
ufw delete 1
Step 9: Verify Listening Services
Check which ports are currently active on the server:
ss -tulnp
This command displays active TCP and UDP listening services.
Properly managing firewall ports on Ubuntu 26.04 helps maintain server security while ensuring applications and public services remain reachable from external networks.
