Docs · Networking

Open ports on Linux

Allow traffic to a port with UFW on Ubuntu and Debian, or firewalld on CentOS.

Linux · 4 min read

Your server has its own dedicated IPv4, and the firewall on it is yours to configure. These steps open a port for an application, such as a web server or a game server.

Always allow SSH (port 22) before enabling a firewall, or your current session may be your last.

Ubuntu and Debian: UFW

UFW (Uncomplicated Firewall) is the simplest option. Install it if it is not already present:

apt install ufw

Allow SSH first, then the ports your application needs:

ufw allow OpenSSH
ufw allow 80/tcp
ufw allow 443/tcp

Turn the firewall on and check the result:

ufw enable
ufw status verbose

Other common examples:

ufw allow 25565/tcp          # a single TCP port
ufw allow 27015/udp          # a single UDP port
ufw allow 30000:30100/tcp    # a range of ports
ufw delete allow 80/tcp      # remove a rule

CentOS: firewalld

CentOS uses firewalld. Check it is running with systemctl status firewalld, and start it with systemctl enable --now firewalld if not. Add a port to the permanent configuration, then reload:

firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=443/tcp
firewall-cmd --reload

List what is open:

firewall-cmd --list-all

Remove a port:

firewall-cmd --permanent --remove-port=80/tcp
firewall-cmd --reload

Check the application is listening

A firewall rule does nothing if no program is listening on the port. Check with:

ss -tulpn | grep :80

If the application is bound to 127.0.0.1, it only accepts local connections. Configure it to listen on 0.0.0.0 (all addresses) or on your server’s public IPv4.

Remember that the acceptable use policy applies to whatever you expose.