How to ping a specific port number?
The system administrators or the operation guys need to make sure that a service is running all the time. When it comes to a network or remote monitoring, the technical operator needs to check if a service listening for a request on the request.
By pinging a specific port on the server from a remote machine lets know that service is up or down. Port number in the computer network is a numeric value (e.g 3425).
A network service is a software application that listens to a specific port number for a request. Once a request is received on that port it replies.
A database service, web server, or web application are few examples of network applications. A server may host multiple services using different port numbers.
In real life example, browsing a web page (e.g www.cspsprotocol.com) is an example where the website runs over port 80 on the hosting server for a domain and a web browser requests a web page.
We have an icmp protocol ping command to check IP a host is reachable or not. But it only lets us know that the hosting server is up and running. It is not sufficient to check if a specific service is running or not on that host.
Pinging a port is the way, where we can check remotely if a serving is listing on a port or not. In this tutorial, we are explaining how to ping a port in different ways.
Use telnet to ping a specific port.
Telnet is the basic command on Windows and Linux operating systems to do a remote login. It is an application layer protocol that uses TCP/IP as the base transport protocol. Telnet needs an IP address and a port number, default it uses port number 23. To ping a specific port using telnet, we need to use the following command.
# telnet <IP_Address> <PortNumber>
In place of IP address, you can also use the domain name. Let’s see how a response to ping port 80 on the host www.google.com.
# telnet www.google.com 80 Trying 220.127.116.11... Connected to www.google.com. Escape character is '^]'. ^C
The telnet command is part of Windows, but on Linux a secure version of remote login named ssh is available. If your Linux operating system does not have the command then use the following to install it.
#yum install telnet
To exit from telenet type q.
Use Netcat(nc) command to ping a specific port.
The Linux has
nc command to perform activities for UDP, TCP, and other sockets types. It can do port scanning and other activities. Port scanning means checking if a port is opened and can be used for a data transfer. If the Linux does not have nc command, you can install it with the yum.
# yum install nc
Following is the use of nc to check ports on host www.google.com.
# nc -vz www.google.com 80 Ncat: Version 7.50 ( https://nmap.org/ncat ) Ncat: Connected to 18.104.22.168:80. Ncat: 0 bytes sent, 0 bytes received in 0.05 seconds.
Connect on port 80. So the port is opened.
Now connect on port 500.
# nc -vz www.google.com 500 Ncat: Version 7.50 ( https://nmap.org/ncat ) Ncat: Connection to 22.214.171.124 failed: Connection timed out. Ncat: Trying next address... Ncat: Network is unreachable.
Connection Fails. The Port is not open.