How to ping a specific port number?
The system administrators or the operation guys must ensure a network service is constantly running. The service could be locally or on a distance machine that you cannot access. When monitoring a network application from the remote, the technical operator must check if a service is listening for a request on the server machine.
Pinging a specific port on the server from a remote machine lets us know whether the service on that Port is up or down. A port number in the computer network is a two bytes 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 processes and may send back a reply.
A database service, web servers, or web applications are a few examples of network applications. A server may execute many services over the same host by assigning distinct port numbers to different applications.
For example, browsing a web page (e.g., domain www.cspsprotocol.com) is an example where the website runs over the default HTTP port 80 on the domain hosting server.
The ICMP protocol provides a ping command to check whether a host is reachable. But it only lets us know that the hosting server is up and running. It is not suitable to check whether a specific service is up on that host.
Pinging a port is checking remotely if a serving is listening on a port. This tutorial will explain multiple methods to ping a port remotely.
Use telnet to ping a specific port.
Telnet is the basic command on Windows and Linux operating systems to do a remote login. An application layer protocol uses TCP/IP as the base transport protocol. Telnet needs an IP address and a port number. By default, it uses port number 23. To ping a specific port using telnet, we need to use the following command.
# telnet <IP_Address> <PortNumber>
You can also use the domain name in place of an IP address. Let’s see how a response to ping port 80 on the host www.google.com.
# telnet www.google.com 80 Trying 142.250.192.228... 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, install the following.
#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 socket 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 Linux does not have the nc
command, you can install it with the yum.
# yum install nc
Following is the use of nc
command 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 142.250.192.196: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 142.250.192.196 failed: Connection timed out. Ncat: Trying next address... Ncat: Network is unreachable.
Connection Fails. The Port is not open.
Do we have other utilities to ping a specific port?
We can use utilities such as Nmap on Linux and Powershell on Windows. But telnet is preferable as this is the basic and legacy command on all operating systems.