Why can't I ping the port number? How to verify that the port number is available?
Why can't I ping the port number? How to verify that the port number is available?
1. Why can’t I ping the port number?
Ping is a network tool often used to test whether the network connection between two computers is normal. Ping uses the Internet Control Message Protocol (ICMP) to send ICMP request messages to the target computer. If the target computer is working properly and connected to the network, it will reply with an ICMP response message. This is a tool commonly used to test network reachability and measure network latency.
However, Ping is not a tool for testing network connectivity by port number. It uses the ICMP protocol instead of traditional port number-based protocols such as Transmission Control Protocol (TCP) or User Datagram Protocol (UDP). Therefore, Ping does not test against a specific port number, but rather tests whether the target computer is able to respond to ICMP requests.
To sum up, ping cannot verify whether the system port number is available. The main reasons are as follows:
- The protocol is different: Ping uses the ICMP protocol instead of TCP or UDP. System port numbers are usually associated with TCP or UDP protocols. Therefore, Ping cannot test whether a specific port is listening.
- ICMP requests have nothing to do with port numbers: The ICMP request message sent by Ping is a detection tool used to test network reachability. It just sends a message to the target host and requests a simple reply. It does not contain information related to the port number.
- Port is a transport layer concept: Port number is a concept in transport layer protocols (such as TCP and UDP) and is used to distinguish different network applications or services. Ping is located at the network layer and is more focused on testing the reachability between hosts and does not care about the ports on the transport layer.
2. How to verify that the port number is available?
Common tools used to verify whether the port number is available include telnet, curl, nc (netcat), nmap, etc.
Use telnet to verify the port:
[root@localhost ~]# telnet 192.168.15.137 22
Trying 192.168.15.137...
Connected to 192.168.15.137.
Escape character is '^]'.
SSH-2.0-OpenSSH_7.4
Connection closed by foreign host.
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
Use curl to verify the port (or call telnet to achieve it):
[root@localhost ~]# curl -v telnet://192.168.15.137:22
* About to connect() to 192.168.15.137 port 22 (#0)
* Trying 192.168.15.137...
* Connected to 192.168.15.137 (192.168.15.137) port 22 (#0)
SSH-2.0-OpenSSH_7.4
* Send failure: Broken pipe
* Closing connection 0
curl: (55) Send failure: Broken pipe
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
Use curl to verify the port:
[root@localhost ~]# curl 192.168.15.137:22
SSH-2.0-OpenSSH_7.4
Protocol mismatch.
curl: (56) Recv failure: Connection reset by peer
- 1.
- 2.
- 3.
- 4.
Use nc to verify the port:
[root@localhost ~]# nc -zv 192.168.15.137 22
Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connected to 192.168.15.137:22.
Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.
- 1.
- 2.
- 3.
- 4.
- Use nmap to verify the port:
[root@localhost ~]# nmap -p 22 192.168.15.137
Starting Nmap 6.40 ( http://nmap.org ) at 2023-10-10 15:13 CST
Nmap scan report for 192.168.15.137
Host is up (0.000057s latency).
PORT STATE SERVICE
22/tcp open ssh
Nmap done: 1 IP address (1 host up) scanned in 0.26 seconds
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
Summarize
Tools such as ping, telnet, curl, nc, and nmap have different functions and uses. They are all used frequently in work. They can greatly improve our work efficiency. Have you learned it?