Managing firewall rules is essential for controlling network traffic and ensuring security on an Ubuntu server. This guide will show you how to open specific ports using ufw
(Uncomplicated Firewall), the default firewall management tool in Ubuntu.
Ubuntu comes with ufw
preinstalled. To verify if it’s active, run:
sudo ufw status
If the firewall is active, it will show a list of rules.
If it's inactive, enable it with:
sudo ufw enable
To open a specific port, use the following command:
sudo ufw allow <port_number>
For example, to allow HTTP traffic on port 80:
sudo ufw allow 80
You can specify the protocol (TCP
or UDP
) when opening a port:
sudo ufw allow 443/tcp # Opens port 443 for HTTPS traffic
sudo ufw allow 53/udp # Opens port 53 for DNS queries
To allow access from a specific IP address (e.g., 192.168.1.100
) to a port:
sudo ufw allow from 192.168.1.100 to any port 22
To open a range of ports, use:
sudo ufw allow 5000:6000/tcp
If you need to close an open port, use:
sudo ufw delete allow 80
After making changes, reload UFW to apply them:
sudo ufw reload
To list all active rules:
sudo ufw status numbered