Firewall

Linux Check if Port is blocked by Firewall

At times when you are trying to connect to a web server, the connection request fails. There could be several different reasons for this; however, one probable reason is that your Firewall blocks the port number you are trying to connect. This article will be learning two different checking methods if the Firewall blocks the specified port or not in Linux Mint 20.

Methods of Checking if a Port is blocked by Firewall in Linux Mint 20:

For checking if a port is blocked by the Firewall in Linux Mint 20 or not, you can follow either of the two methods described below:

Method # 1: Using the “netcat” Utility to check if a Port is blocked by Firewall in Linux Mint 20:

For using the “netcat” utility to check if the Firewall blocks a port in Linux Mint 20, you will have to execute the following command:

$ nc –zv HostName PortNumber

Here, you will have to replace HostName with the website’s hostname that you are trying to reach and PortNumber with the actual port number that you want to check is blocked or not by the Firewall. For demonstration, we have replaced HostName with google.com and PortNumber with 80, as shown in the image below:

From the output shown in the following image, the connection to google.com on port number 80 was successful, which indicates that the Firewall does not block this port in Linux Mint 20.

Method # 2: Using the “telnet” Utility to check if a Port is blocked by Firewall in Linux Mint 20:

For using the “telnet” utility to check if the Firewall blocks a port in Linux Mint 20, you will have to execute the following command:

$ telnet HostName PortNumber

Here, you will have to replace HostName with the website’s hostname that you are trying to reach and PortNumber with the actual port number that you want to check is blocked or not by the Firewall. For demonstration, we have replaced HostName with google.com and PortNumber with 80, as shown in the image below:

From the output shown in the following image, the connection to google.com on port number 80 was successful, which indicates that the Firewall does not block this port in Linux Mint 20.

Conclusion:

By using any of the two ways discussed in this article, you will easily be able to figure out within a few seconds if a specified port is blocked by your Firewall or not. In this way, you will be able to know the actual cause of your web server connection failures.

About the author

Karim Buzdar

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.