The objective of this article is to serve as a quick reference guide on how to allow incoming traffic on any TCP or UDP port using Ubuntu 20.04 Focal Fossa 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
Example of how to Open/Allow incoming firewall port 53 on Ubuntu 20.04 Focal Fossa
Example of how to Open/Allow incoming firewall port 53 on Ubuntu 20.04 Focal Fossa

Software Requirements and Conventions Used

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Installed or upgraded Ubuntu 20.04 Focal Fossa
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 20.04 examples

  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. SUBSCRIBE TO NEWSLETTER
    Subscribe to Linux Career NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


  4. 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
  5. 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
    
  6. Open port for a specific webserver such as Apache or Nginx execute the bellow Linux command:
    $ sudo ufw allow in "Apache Full"
    $ sudo ufw allow in "Nginx Full"
    
  7. Open port for a specific service such as SSH:
    $ sudo ufw allow in ssh
    
FIND LATEST LINUX JOBS on LinuxCareers.com
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.

You may also be interested in:



Comments and Discussions