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

How will 5G technology change application development?

Technology is constantly evolving, and it's e...

Approaches to Solving Multiradio Hardware Design Challenges

The combination of multi-radio and multi-protocol...

5G deployment plan postponed to 2021, will operators agree?

In 2020, the sudden outbreak of COVID-19 is havin...

IPv6 Multicast Technology and Dual Protocol Stack Technology

1. IPv6 Multicast Technology IP multicast is an e...

Blockchain, IoT and 5G

5G networks are starting to roll out across the U...

The story behind 2.5 million 5G users in 5 months

[[275646]] South Korea's 5G development speed...

JD.com's Lv Jianwei: Black technology leads the new era of e-commerce

[51CTO.com original article] On July 21-22, 2017,...

Can you tell me about Zookeeper's ZAB protocol? Sorry, I have a stomachache!

This article is reproduced from the WeChat public...

How to force close TCP connection in Go

[[425673]] This article is reprinted from the WeC...

Finding strength in numbers: Data center agglomeration effect

In the past, data centers were often built in rem...