1. Home
  2. Linux

How to port forward through the firewall on Ubuntu

Do you use the Ubuntu firewall and need to open up ports to the internet on your system? We can help! Follow along with this guide as we go over ways you can port forward on Ubuntu!

Note: although this guide focuses on Ubuntu, it will also work on any Linux OS based upon Ubuntu as they also have access to the same firewall.

port forward on Ubuntu

Need to block ports? Try this guide.

Port forward on Ubuntu – GUI

The easiest way to port forward through the firewall on Ubuntu is by using the GUI. The GUI for the Ubuntu firewall acts as a go-between to the command line. Essentially, it gives a nice interface to the command-line app.

To interact with the Ubuntu firewall with a GUI, you will need to have the GUFW app installed on your system if you don’t already. To install GUFW on your Ubuntu PC, start by opening up a terminal window. 

You can open up a terminal window by pressing Ctrl + Alt + T on the keyboard. Or, alternatively, you can search for “Terminal” in the Ubuntu app menu. Once the terminal window is open and ready to use, use the apt install command to get GUFW.

sudo apt install gufw

If you’re not a fan of using the terminal to install apps, don’t worry! You can install it using Ubuntu Software. To start, open up the “Ubuntu Software” application. Once it is open, find the search icon, and click on it with the mouse.

In the search box, type in “GUFW” and press the Enter key. By pressing Enter, you’ll be presented with search results. Look through the results for “Firewall Configuration” and click on it.

Upon clicking on “Firewall” configuration, you will go to the app’s Ubuntu Software page. Click on the “INSTALL” button to download and install the software on your computer.

Configuring port forwarding in GUFW

Now that the GUFW application is installed on your Ubuntu PC, you can use it to forward ports outside of the firewall. To do it, follow the step-by-step instructions below.

Step 1: Open up GUFW by searching for “Firewall Configuration” in the Ubuntu app menu. Once it is open, look for the “Status” slider. Click it to enable protection if you do not have it on already.

Step 2: Find the “Rules” button in GUFW, and click on it to access the rules area. From here, select the “+” icon. By clicking on this icon, you’ll open up the “Add a Firewall Rule” window.

Step 3: In the new rule window, find the “Simple” tab, and click on it. In the tab, find “Direction” and change it to “Out.” By setting it to out, you’re allowing Ubuntu to “port forward” to the internet. 

Step 4: Find the “Port” box, and click on it with the mouse. From there, find the “Port or service” box and type in the port. When you’ve finished writing out the port number, click on the “Add” button to add the new rule.

Once you’ve added in your port number, the firewall should instantly allow it through. However, if it is not instant, feel free to reboot your PC to fix the problem.

Port forward on Ubuntu – CLI

In addition to port forwarding with the GUI, it is also possible to port forward in the Ubuntu firewall using the CLI (AKA the terminal). To do this, start by confirming you have the UFW firewall enabled on your system.

To confirm you have the UFW firewall enabled, open up a terminal window. You can open up a terminal window by pressing Ctrl + Alt + T on the keyboard or by searching for “terminal” in the app menu.

With the terminal window open, use the sudo ufw enable command to enable the firewall if it is turned off for some reason. If your UFW is already enabled, do not worry. You can skip this step.

After confirming that the UFW firewall is operational, use the ufw allow command to port forward. For example, if you are hosting an OpenSSH server on your Ubuntu PC, you will need to open up port 22 to the internet. To do that, you can enter the command below.

sudo ufw allow 22/tcp

Or, if you need to allow connections on port 32400 out to the internet over UDP, you can do the following command instead. 

sudo ufw allow 32400/udp

Once you’ve added your ports to the Ubuntu firewall, you can check its status to see if the allow commands you’ve entered are running using the ufw status command.

sudo ufw status

Suppose you’re having issues getting port forwarding working on Ubuntu, and the ufw allow commands aren’t working. In that case, you can disable the firewall entirely, exposing all ports to the internet using the ufw disable command.

sudo ufw disable

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.