If you are running an Ubuntu VPS 20.04 server, one of the important tasks you need to perform is opening ports on the firewall to allow incoming and outgoing traffic to your server. This is especially important if you are running services such as HTTP, HTTPS, SSH, FTP, etc. In this tutorial, I will show you how to open ports on the Ubuntu 20.04 firewall using UFW (Uncomplicated Firewall), commonly used on Linux VPS.

Step 1: Check the firewall status of your VPS

Before opening ports on the firewall, you need to check whether the firewall is enabled or not. You can do this by running the following command in the terminal:

sudo ufw status

If the firewall is enabled, you will see the following message:

Status: active

If the firewall is disabled, you will see the following message:

Status: inactive

Step 2: Add inbound rules

To add an inbound rule for a specific port, use the following command:

sudo ufw allow {porta}/{protocolo}

Replace {porta} with the port you want to open and {protocolo} with the corresponding protocol (tcp or udp). For example, if you want to open port 80 for HTTP traffic, run the following command:

sudo ufw allow 80/tcp

To open multiple ports at the same time, separate the ports with commas. For example, to open ports 80, 443 and 8080, run the following command:

sudo ufw allow 80,443,8080/tcp

Step 3: Add outbound rules

If you want to allow outgoing traffic for a specific port, use the following command:

sudo ufw allow out {porta}/{protocolo}

For example, to allow outgoing traffic on port 80, run the following command:

sudo ufw allow out 80/tcp

Step 4: Enable the Firewall

If you have just installed Ubuntu 20.04 and have not yet enabled the firewall, you can enable it using the following command:

sudo ufw enable

Step 5: Check the firewall rules

To check all firewall rules, run the following command:

sudo ufw status

You will see a list of all the firewall rules that have been added. Make sure the ports you just opened are listed.


Conclusion

Opening ports on the firewall is an important task to ensure that your services can be accessed securely and in a controlled manner on your Linux VPS. UFW is an easy-to-use tool for managing the firewall on an Ubuntu VPS 20.04. With this tutorial, you should be ready to add inbound and outbound rules and enable the firewall on your VPS server.

Was this answer helpful? 138 Users Found This Useful (440 Votes)