Knowledge Base Hub

Browse through our helpful how-to guides to get the fastest solutions to your technical issues.

Home  >  How-Tos  >  How To Open Ports On Ubuntu
Top Scroll

How To Open Ports On Ubuntu

 4 min

Opening your specific web server ports is important so network services can respond accordingly to the outside world for communication. Enabling incoming traffic on the designated ports allows you to have services like web servers (HTTP and HTTPS) as well as services through FTP, SSH, and others. 

Bear in mind that simply opening some ports eventually exposes your server to security risks. Hence, the need to open only critical ports with adequate security systems to protect the system is placed utmost priority. 

Understanding UFW: The Ubuntu Firewall

UFW is a simple way to work on the interface for Ubuntu’s firewall rules. UFW can block or accept the incoming or outgoing traffic according to how the rules are set up and might provide a little extra help to add security to the system.

In simple words, if a user sets personal rules using UFW, then the advanced technology will begin filtering incoming and outgoing traffic according to the set rules, just like the working of a very common email filter segregating e-mail.

UFW is a command-line setup utility for Linux firewalls. It comes pre-installed with Ubuntu and Debian 10 or later but is disabled by default. This Uncomplicated Firewall, or UFW, supports the CLI and utilizes iptables configuration.

Risks Associated with Ports:

Port opening has the risk of compromising security if done incorrectly. These risks should be mitigated:

  1. By only opening the necessary ports. Avoiding the ports that are not required to open can save you from potential harm. 
  2. By using security best practices and strong security measures, such as using robust passwords and keeping software up-to-date. This will not allow strangers to access your computer and network traffic; monitor your system for suspicious activity.

How do I open ports on Ubuntu?

Opening ports is part of the installation or setup procedure for most network services, including web servers, FTP servers, and SSH. Such operations should be run, however, only after one has gained an understanding of the risks.

While the process of opening a port for an HTTP and HTTPS server is relatively similar to what happens in AlmaLinux/Rocky Linux, however, by default, Ubuntu relies on using the ufw-uncomplicated firewall, which is a user-friendly firewall tool. Here’s how to open ports using this ufw tool:

Opening port using ufw:

  1. Open Terminal: Press Ctrl + Alt + T on your keyboard or search for it in the applications menu. It will open the terminal.
  2. Status of ufw: As Ubuntu comes with a ufw firewall pre-installed, it’s important to check its status. You can confirm the status of the Ubuntu firewall by using the command:
sudo ufw status
  1. Allow HTTP and HTTPS traffic: Now set the HTTP (port 80) and HTTPS (port 443) to receive traffic. Remember Ubuntu firewall is pre-set to identify ports and enable them; if the ports are not enabled by default, allow them by using the command: 

sudo ufw allow http

sudo ufw allow https

TCP is the default protocol, but you can specify your own with /protocol syntax, for example:

sudo ufw allow 8080/tcp

The above command allows incoming TCP connections on port 8080.

Or, to allow incoming UDP connections on port 53 (DNS):

sudo ufw allow 53/udp
  1. Enable the Changes
sudo ufw enable
  1. Confirm the changes.

It is essential to confirm the changes that you implement. Following the addition of the rule, verify that the port is allowed by running:

sudo ufw status

You should now see a line that shows the status of the port you just allowed. Use the same steps for each other port you wish to open.

Closing port using ufw:

  1. To close the ports, use the below commands:
sudo ufw deny http
sudo ufw deny https
  1. Lastly, when you need to open/close specific ports, just replace the desired port number with actual port numbers when appropriate.
sudo ufw allow 8080/tcp

Click here to learn more about the Ubuntu firewall.

Last line

In conclusion, opening ports on Ubuntu using UFW is quite straightforward and will certainly make management of the different network traffic configurations in your system much easier, with an improvement in security.

With this guide, it becomes easy for users to configure UFW and allow or block incoming and outgoing traffic according to their needs. Another security layer it provides is its integration with Ubuntu’s AppArmor, which gives more security to the applications running on the system. It doesn’t matter whether you are a novice or a highly experienced Linux user; UFW will make the task of handling your firewall quite simple and keep your system secure.

For our Knowledge Base visitors only
Get 10% OFF on Hosting
Special Offer!
30
MINS
59
SECS
Claim the discount before it’s too late. Use the coupon code:
STORYSAVER
Note: Copy the coupon code and apply it on checkout.