Open Firewall Ports in Ubuntu

How to open firewall ports in Ubuntu

Use the ufw command to open firewall ports in Ubuntu. The syntax is as follows:

sudo ufw allow port

See the examples below and apply specific ports for the services you need to open. Remember, you don’t want to open anything that isn’t absolutely necessary. I treat all networks as “zero trust” networks and every zone as a DMZ.

How do I open tcp port # 22?

To allow incoming tcp packets on port 22, enter:
sudo ufw allow 22/tcp

Verify it:
sudo ufw status verbose

How do I open tcp port # 80 and 443?

The service specific syntax is as follows to open http and https service ports:
sudo ufw allow http
sudo ufw allow https

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp


I use these rules to configure servers for services like Jamf-Pro, which recommends that certain ports are open for the services that it uses. Refer to your vendor or developer documentation to find out more about the services you need on your own server.