How to Open/Allow incoming firewall port on Ubuntu 22.04 Jammy Jellyfish

The default firewall on Ubuntu 22.04 Jammy Jellyfish is ufw, which is short for “uncomplicated firewall.” When enabled, the firewall will block all incoming connections by default.

If you want to allow an incoming connection through ufw, you will have to create a new rule to allow a certain port or multiple ports. We can also specify that only connections from a certain IP address or network range can gain incoming access, while blocking all others. This is all done from the command line and is quite simple once you know the proper syntax.

The objective of this tutorial is to serve as a quick reference guide on how to allow incoming traffic on any TCP or UDP port using Ubuntu 22.04 Jammy Jellyfish Linux with UFW firewall.

In this tutorial you will learn:

  • How to open port to any source
  • How to open port to specific IP address or subnet
  • How to open UDP port
  • How to open TCP port
Example of how to Open/Allow incoming firewall port 53 on Ubuntu 22.04 Jammy Jellyfish
Example of how to Open/Allow incoming firewall port 53 on Ubuntu 22.04 Jammy Jellyfish
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Ubuntu 22.04 Jammy Jellyfish
Software ufw
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

How to Open/Allow incoming firewall port on Ubuntu 22.04 examples



Twitter icon Follow LinuxConfig.org on Twitter for the latest tips and tricks about Linux!


Check out the various examples below to learn how the syntax works for allowing ports, IP addresses, and subnets through the ufw firewall on Ubuntu 22.04. Note that you will need to execute the following commands with root permissions.

  1. Open incoming TCP port 53 to any source IP address:
    $ sudo ufw allow from any to any port 53 proto tcp
    
  2. Open incoming TCP port 443 to only specific source IP address eg. 10.1.1.222:
    $ sudo ufw allow from 10.1.1.222 to any port 443 proto tcp
    
  3. Open incoming UDP port 53 to source subnet eg. 10.1.1.0/8:
    $ sudo ufw allow from 10.1.1.0/8 to any port 53 proto udp
    
  4. Open incoming TCP ports 20 and 21 from any source, such as when running FTP server:
    $ sudo ufw allow from any to any port 20,21 proto tcp
    
  5. Open port for a specific web server such as Apache or Nginx execute the below Linux command:
    $ sudo ufw allow in "Apache Full"
    $ sudo ufw allow in "Nginx Full"
    
  6. Open port for a specific service such as SSH:
    $ sudo ufw allow in ssh
    

Closing Thoughts

In this tutorial, we saw how to open/allow incoming traffic through the ufw firewall on Ubuntu 22.04 Jammy Jellyfish Linux. This included allowing TCP or UDP, one port or multiple ports, and traffic from a specific IP address or subnet. Keep in mind that more complex configuration (such at NAT) of UFW is also possible, as you can see in our other tutorial: How to Install and Use UFW Firewall on Linux.




If you need to remove any of the added rules in the future, see our other tutorial on How to delete UFW firewall rules on Ubuntu 22.04 Jammy Jellyfish Linux.