How To Ubuntu Linux Firewall Open Port Command

How do I open port 80 and 443 on a Ubuntu Linux LTS version 14.04 server?

Ubuntu Linux server comes with firewall configuration tool called ufw (Uncomplicated Firewall). It is the default tool. ufw is very easy to use and configure host based firewall settings.

Ubuntu Linux firewall open port command

The program is for managing a Linux firewall is ufw. It aims to provide an easy to use interface for the user/sysadmins and developers. For example:

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements ufw
Est. reading time 5m
  1. You can open/close ports with ufw allow command.
  2. Block an IPv4/IPv6 address.
  3. Delete existing firewall rules.
  4. Turn on or off firewall logs.
  5. And more.

Let us see some examples of ufw firewall to open port on Ubuntu server.

How do I see the current status of my firewall?

Type the following command:
sudo ufw status verbose
Sample outputs:

Fig.01: Check the status of UFW on a Ubuntu Linux

Here is another outputs showing various open ports and their status via the ufw command:
To                         Action      From
--                         ------      ----
22/tcp                     ALLOW             # Open TCP SSH PORT for SG_OFFICE
22/tcp                     ALLOW       35.yyy.zzz.ttt             # Open TCP SSH PORT for BACKUP_SERVICE
22/tcp                     ALLOW             # Open TCP SSH PORT for MUM_OFFICE_VPN 642/tcp    ALLOW            # Open tinc TCP port pmdb1:642 for pmdb2 host 642/udp    ALLOW            # Open tinc UDP port pmdb1:642 for pmdb2 host 642/tcp    ALLOW            # Open tinc TCP port pmdb1:642 for pmdb3 host 642/udp    ALLOW            # Open tinc UDP port pmdb1:642 for pmdb3 host                ALLOW             # Allow full communication                ALLOW             # Allow full communication                ALLOW             # Allow full communication 

How do I open tcp port # 22?

To allow incoming tcp packets on port 22, enter:
sudo ufw allow 22/tcp
Verify it:
sudo ufw status verbose

How do I open tcp port # 80 and 443?

The service specific syntax is as follows to open http and https service ports:
sudo ufw allow http
sudo ufw allow https

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

How do I open tcp and udp port # 53?

To allow incoming tcp and udp packet on port 53, enter:
sudo ufw allow 53
Verify it:
sudo ufw status verbose

Advanced examples for opening TCP and UDP ports

To allow IP address access to port 22 for all protocols
sudo ufw allow from to any port 22
Open port (SSL 443 nginx/apache/lighttpd server) for all, enter:
sudo ufw allow from any to port 443 proto tcp
To allows subnet to Sabma services, enter:
ufw allow from to any app Samba
You can find service info as follows:
sudo ufw app list
Sample outputs:

Available applications:
  Nginx Full
  Nginx HTTP
  Nginx HTTPS

To get information on Squid profile/app, run:
ufw app info Squid
Sample outputs:

Profile: Squid
Title: Squid proxy cache
Description: Internet object cache (WWW proxy cache)

Denying/blocking port access

We can add deny rule as follows to block all access to port 25:
sudo ufw deny 25
sudo ufw deny 25/tcp comment 'Block access to smptd by default'

How to delete ufw rules

We can list firewall rules using the following syntax on Ubuntu Linux:
sudo ufw status
sudo ufw numbered

Once we found firewall rule number delete by that number:
sudo ufw delete {num}
sudo ufw delete 5

Another option is to type:
ufw delete deny 25/tcp comment 'Block access to smptd by default'


In this page, you learned how to open TCP and UDP ports using UFW which is a default firewall management tool on Ubuntu Linux. See ufw command man page for more info and all other my tutorials below:

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 6 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
6 comments… add one
  • muhammed Aug 4, 2015 @ 11:50

    Dear Guru,
    i need step in installing
    Pydio on the Linux server.

  • Jouni "rautamiekka" Järvinen Aug 4, 2015 @ 14:52

    UFW isn’t good enough, so we’re not using it, instead learning “iptables”

    • Svenv Mar 3, 2016 @ 13:03

      UFW is just a frontend to iptables, fine for simple config, won’t prevent you from doing advanced iptables stuff.

  • Ravi Aug 5, 2015 @ 2:06

    This was an informative article. Thanks.

  • Carol Spears Aug 6, 2015 @ 2:51

    UFW was as complicated to learn as iptables.

  • Fábio Aug 10, 2015 @ 23:26

    Nice article. I sometimes configure UFW, but I think it´s better just to work directly with iptables. Thank you.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum