List Open or closed Ports in UFW Firewall on Ubuntu

See the commands of the UFW firewall on Ubuntu Linux to list the open ports that are allowed or denied to be accessed from outside the network. 

UFW stands for uncomplicated firewall. The goal of UFW is to provide an uncomplicated command line-based frontend for the very powerful, but not exactly easy-to-configure IPtables. UFW supports both IPv4 and IPv6.

It is quite easy to install because it is included in the package sources – at least if you are using an Ubuntu or Debian distribution. Also, those who are not familiar with the command line can use the graphical user interface known as GUFW, also available to install using the default repository of Ubuntu. It makes us easily manage inbound and outbound traffic using firewall rules.

Command to Check all open ports in the UFW Firewall

1. List Open or closed Ports in UFW

If you don’t want to know what are the ports already opened in your system firewall i.e UFW, simply open the command terminal and use the given command:

sudo ufw status verbose

Note: Ports with the “Allow in” action are opened whereas the ones with “Deny in” are closed.

List UFW firewall ports open

2. How to delete rules in UFW

If there is any rule you have added to open some port in UFW and now want to delete that rule; for that, you can simply use the added rule’s serial number and a ‘delete’ parameter.

List all ports with their serial number

sudo ufw status numbered

Now, the rule that you want to delete- note down its serial number and use it with the given command:

For example, if you want to delete a rule specified with serial number 8, then the command will be:

sudo ufw delete 8
Check rules number in UFW

3. How to Open a new port

Also, for those who want to know the command to open any new port using the UFW command line, then here is the syntax:

sudo ufw allow port-number

for example, if you want to open port 443, the above syntax will be:

sudo ufw allow 443

4. Close or Deny Ports in UFW

In case, instead of deleting rules you just want to close the access of some particular port on your system from the outside network, then the syntax is:

sudo ufw deny port-number

Example:

sudo ufw deny 443

5. Install GUI for UFW

Well, there is an easy way to manage rules in the UFW Firewall by installing a graphical user interface for it. If you are on Ubuntu then here is the command for that:

sudo apt install gufw

Other Articles:

How to Open or close ports in AlmaLinux 8 or Rocky Firewall
Install and Configure UFW Firewall on Debian 11
How To Install SFTPGo on Ubuntu 22.04 LTS

Leave a Comment

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