Linux Commands

How do I Ping a Specific Port?

We shall take “ping a specific port” to mean that you want to verify a specific port’s status for a given IP address. This is useful for troubleshooting why a service is not working properly.

This article will show you how to verify a specific network port’s status by using Netcat, Nmap, and Nping.

Ping a Specific Port with Netcat

The Netcat tool is used to retrieve information about network connections and listens.

If Netcat is not installed on your Linux machine, run the command below:

Ubuntu/Debian based systems:

$ sudo apt install netcat

CentOS/Red Hat based systems:

$ sudo dnf install nc

Or try

$ sudo dnf install netcat

You may use Netcat to ping a specific port as follows.

nc -vz <IP> <Port>

Replace <IP> and <Port> as appropriate.

For example:

$ nc -vz 192.168.0.1 22

Figure 1 – Ping a specific port with Netcat

For more options and additional help using Netcat, run the command below.

$ nc -h

Ping a Specific Port with the Nmap tool

The Nmap tool is typically used to scan a network host to obtain information about available ports and services.

If the Nmap tool is not already installed on your Linux machine, run the command below:

Ubuntu/Debian based systems:

$ sudo apt install nmap

CentOS/Red Hat based systems:

$ sudo dnf install nmap

Now, you may use Nmap to ping a specific port. The syntax i.

nmap -p<Port> <IP>

For example:

$ sudo nmap -p80 192.168.0.1

Figure – Ping a specific port with nmap

For additional options and help using Nmap, run the command below.

$ nmap -h

Ping a Specific Port with Nping

Nping is part of Nmap and works somewhat similar to the standard ping utility. You can use the Nping tool to ping a specific port as follows.

nping -p<Port> <IP>

For example:

$ nping -p22 192.168.0.1

Figure 2 – Ping a specific port with Nping

For additional options and help using Nping, run the command below.

$ nping -h

Conclusion

This article showed you how to ping a specific port with Netcat, Nmap, and Nping. Do let us know which of these tools works best for you.

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.