Linux Commands

Linux Check If Port Is Blocked by Firewall

We all know that network communication occurs because of the ports and sockets. A port allows you to connect to the desired web server at any time you want while using the Internet. However, there are times that the firewall running on your system blocks certain ports due to security concerns. Therefore, if you ever wish to find out whether your firewall blocks a certain port or not in Linux, then you can follow this guide.

How To Check If a Port Is Blocked by the Firewall

To check if a port is blocked by the firewall or not, we are going to share with you two different methods below:

Method # 1: Using the “telnet” Command

In this method, we will try to use the “telnet” command to access a web server on a specific port number to see if our firewall blocks a port. We will use the “telnet” command in the following manner:

$ telnet linuxhint.com 80

Here, “linuxhint.com” is the name of the web server that we wanted to access. Whereas “80” refers to the port number whose status we wish to find out.

The following output implies a successful connection to the specified web server, which means that the specified port is not blocked by our firewall.

Method # 2: Using the “nc” Command

Now, we will use the “nc” command or the “netcat” utility for accessing a web server via a specific port to figure out if that port is blocked by our firewall or not. The “nc” command for this purpose can be used in the following manner:

$ nc –zv linuxhint.com 80

The successful connection message shown in the following image indicates that the specified port is not blocked by our firewall:

Conclusion

By using either of the two methods discussed in this article, you can conveniently find out if a specific port is blocked by your firewall or not. In this way, you will be able to connect to your desired web servers smoothly on a port of your choice.

About the author

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.