How Can I Open Ports on Ubuntu

Open ports are ports that allow traffic from a service or applications to run on it. Opening ports are important if you want a certain service to run on your system. In most systems such as Ubuntu ports are closed by default for security purposes but they can be opened easily.

In this writeup, we have shown how to open ports in Ubuntu.

How Can I Open Some Ports on Ubuntu

To open ports on Ubuntu, we will use an uncomplicated firewall (UFW), which is an Uncomplicated Firewall tool that provides proxy settings in different systems. Many Linux systems come with the pre-installed firewall but in case of Ubuntu it will be required to install.

You can install UFW on Ubuntu from the repository using the apt command and for that, it’s mandatory to update/upgrade the repository first using the below-mentioned commands:

$ sudo apt update
$ sudo apt upgrade


Then install UFW by using the below-mentioned command:

$ sudo apt install ufw


Once the UFW is installed, enable it on your Ubuntu system by using the below-mentioned command:

$ sudo ufw enable


How to Open Port on Ubuntu

Once the UFW is enabled, you can open ports using the below-mentioned command:


$ sudo ufw allow <port>


For example, to open SSH port which is 22 by default, you can use 22 with the ufw command as shown below:

$ sudo ufw allow 22


By using UFW, the traffic to the port can also be controlled and for that the user just has to specify the port along with the protocol name they want the traffic:


$ sudo ufw allow <port>/<protocol>


In the stated example, I have allowed the tcp protocol traffic to port 80.

$ sudo ufw allow 80/tcp


Similarly, the below-written example allows the udp traffic to port 1025:

$ sudo ufw allow 1025/udp


The traffic from a specific IP address can also be allowed to a port by following the below-mentioned command:

$ sudo ufw allow from to any port 21


To check the status of the ports, you can follow the below-mentioned command to verify that ports are opened successfully:

$ sudo ufw status


How to Close Ports on Ubuntu

If you have previously opened a port and now you feel the need to block it then you can use the below-mentioned command:


$ sudo ufw deny <Port>


Just like opening port command, you can also block the ports with either their name or service name:


Blocking ports by using port number:

$ sudo ufw deny 22


Then verify by using the below-mentioned status command:

$ sudo ufw status


That’s all for the process, but remember that while using UFW to open ports, ensure that the service you are interested in the opening should be active.


To open ports in Ubuntu, the users have to install UFW from the apt command and then enable its service on the system. After that, they can use the UFW command to open ports with port numbers and allow the desired protocol traffic to it. They can also check the status of opened and blocked ports using the ufw status command.

About the author

Zahra Zamir

An Electronics graduate who loves to learn and share the knowledge, my passion for my field has helped me grasp complex electronics concepts and now I am here to share them with others.