Why can't I ping the port number? How can I verify that the port number is available?

Why can't I ping the port number? How can I verify that the port number is available?

1. Why can't the port number be pinged?

Ping is a network tool that is 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 that tests 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 for a specific port number, but rather tests whether the target computer can respond to ICMP requests.

In summary, ping cannot verify whether the system port number is available. The main reasons are as follows:

  • Different protocols: Ping uses the ICMP protocol instead of the TCP or UDP protocol. System port numbers are usually associated with the TCP or UDP protocol. Therefore, Ping cannot test whether a specific port is in a listening state.
  • ICMP request has nothing to do with port number: 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) used to distinguish different network applications or services. Ping is at the network layer and is more focused on testing the reachability between hosts, not 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.

Verify the port using telnet:

 [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.

Use curl to verify the port (or call telnet to implement):

 [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

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

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.
  • Verify the port using nmap:
 [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

Summarize

Tools such as ping, telnet, curl, nc, nmap, etc. have different functions and uses. They are frequently used in work and can greatly improve our work efficiency. Have you learned them?

<<:  Emirates du and Huawei jointly launch the world's first "5G-A Smart Home" with 10G network support

>>:  Interviewer asked: What are the functions of the wait and notify methods in threads?

Recommend

Do you know how much power 5G actually consumes?

5G is one of the hottest topics at the moment, an...

US reportedly allows chip sales to Huawei but only for non-5G business

Things have been bad for Huawei since the US ban....

Seven storage mistakes data centers make during consolidation

Mergers and acquisitions are commonplace in today...

How far will eSIM cards go in 2018?

The eSIM card was mentioned as early as 2011. The...

Why does TCP require three handshakes instead of two?

Hello everyone, I am the island owner Xiaofeng. T...

Talking about my cold thoughts on SD-WAN on the crater

SDWAN will be the most valuable investment outlet...

Global spending on 5G network infrastructure nearly doubled in 2020

According to the latest forecast from Gartner, gl...