Checking ports using ping tool in Linux
Quote from HeelpBook on July 29, 2020, 6:14 pmWhen we want to check whether a host is reachable (at all), we can use the ping command:
ping 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 www.google.com:
nping -p 21 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 www.google.com 80
echo $? # returns 0
nc -w 1 www.google.com 1
echo $? # returns 1On Ubuntu and Debian, Netcat can be installed as follows: sudo apt-get install netcat.
When we want to check whether a host is reachable (at all), we can use the ping command:
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.