Questions

Forum Navigation
Please to create posts and topics.

Checking ports using ping tool in Linux

How could I use ping command line tool to check remote ports?

When we want to check whether a host is reachable (at all), we can use the ping command:

ping http://www.google.com

It sends ICMP Echo Requests to the given host and reports how many packages are received and responded to. The option -c can be used to set how many requests are sent.

A disadvantage of ping is that we cannot configure a specific endpoint (= host + port) to ping. More advanced tools offer alternatives.

The following command pings the FTP port of http://www.google.com:

nping -p 21 http://www.google.com

nping belongs to the nmap package. On Ubuntu and Debian, nmap can be installed as follows: sudo apt-get install nmap.

Another tool is Netcat. The advantage of nc is that the error code indicates whether the endpoint was pinged successfully, making it useful for checking endpoint availability in scripts.

nc -w 1 http://www.google.com 80
echo $? # returns 0
nc -w 1 http://www.google.com 1
echo $? # returns 1

On Ubuntu and Debian, Netcat can be installed as follows: sudo apt-get install netcat.