How to open a port on server (iptables, ufw, firewalld)

12.03.2026
Complexity
min.

Summary

To run services (web server, mail, database), you need to open the corresponding ports in the firewall. Below are instructions for iptables, ufw, and firewalld.

Applies to:
✔ VPS
✔ Dedicated servers
✔ Linux (Ubuntu, Debian, CentOS, AlmaLinux)

Determine which firewall is in use

ufw status 2>/dev/null || firewall-cmd --state 2>/dev/null || echo "iptables"

UFW (Ubuntu/Debian)

Open a TCP port:

ufw allow 8080/tcp

Open a UDP port:

ufw allow 51820/udp

Open a port range:

ufw allow 3000:3100/tcp

Open a port for a specific IP only:

ufw allow from 1.2.3.4 to any port 3306

Check rules:

ufw status numbered

firewalld (CentOS/AlmaLinux)

Open a port (permanently):

firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reload

Open a service:

firewall-cmd --permanent --add-service=http
firewall-cmd --reload

Check:

firewall-cmd --list-all

iptables

Open a TCP port:

iptables -A INPUT -p tcp --dport 8080 -j ACCEPT

Open a UDP port:

iptables -A INPUT -p udp --dport 51820 -j ACCEPT

Open a port for a specific IP:

iptables -A INPUT -p tcp -s 1.2.3.4 --dport 3306 -j ACCEPT

Save rules (Ubuntu/Debian):

apt install iptables-persistent -y
netfilter-persistent save

CentOS:

service iptables save

Check rules:

iptables -L -n --line-numbers

Common ports

PortService
22SSH
80HTTP
443HTTPS
3306MySQL
5432PostgreSQL
1500ISPmanager
8888FastPanel
3389RDP

Verification

From another computer:

nc -zv SERVER_IP PORT

On the server, verify the port is listening:

ss -tlnp | grep PORT
Do not open database ports (3306, 5432) to all IPs unless necessary. Restrict access to specific addresses. If you need help configuring the firewall, open a support ticket.
Was this information helpful?
Yes   No
 
By continuing to use this website you will be agreeing to the website Acceptable Use Policy and the Use of Cookies while using the website and our services. Please also read our Privacy Policy under which, to the extent stated, you consent to the processing of your personal data.