I. Writing at the beginning
Recently a student wrote privately that when he went for an interview, he was stumped by a small question from the interviewer, a question about network connectivity, which the interviewer asked the student:
“On a daily basis, how do you test network connectivity between two hosts, network latency, and whether ports are open or not? And tell us the principle"
I've never seen this kind of question in the interviews I've been through, it's too small after all, it's not a question for any programmer with work experience, but if you ask me to go into how they work, I'd be stumped for a moment, not that I'm too much of a noob, but the interviewer is being unreasonable!
II. PING
2.1 Use of PING
Ping is a very, very common network testing tool, often used to test the connectivity and network latency between hosts in a network. It is commonly used on both Windows and Linux systems.
Usage: ping ip or ping domain name
We can type "ping /?" in a DOS window. in a DOS window to open the command help page, which will help us to use the command better.
Now, let's take Baidu as an example of a URL that we ping:
As shown in the figure above is our local ping Baidu domain name of a process and feedback results, visible network connectivity is good, the response time of 18ms, if the time is too long, indicating that the network latency is large, we can also be -n or -i and -t to test the network carrying capacity.
2.2 Principles of PING
The principle of the ping command to detect network connectivity relies heavily on network layer ICMP (Internet Control Message Protocol (ICMP)) protocol implementation. The main form is by sending ICMP request messages and receiving ICMP response messages to the target host. If the request is for a domain name, it is resolved to the IP address of the corresponding host through the DNS domain name system, and then the message is sent.
- The PING command sends an ICMP Echo Request to the target host.
- If the connectivity between the two hosts is normal, the target host returns a corresponding ICMP Echo Reply.
III. Telnet
telnet(rlogin protocol), which is an application layer protocol based on the TCP protocol, is often used to test networks and port occupancy. We are able to test the network and port occupancy bytelnet ip port
command to connect to the remote server. A failed connection means that the port is not occupied. Otherwise, the port is occupied.
One of the biggest drawbacks of the Telnet protocol is that all data (including usernames and passwords) is sent in clear text, which is a potential security risk. This is the main reason why Telnet is seldom used today, in favor of a very secure network transport protocol called SSH.