当前位置:网站首页>Ping principle
Ping principle
2022-07-29 06:49:00 【Flytiger1220】
I've read a lot of interview questions recently , Among them, I was also asked about ping And some principled things , So I read many people's blogs , Finally, it suddenly became clear , Decided to sum up , Also to prevent forgetting .
To understand ping Principle , Let's take a look first ARP The message format of 
among op:
1: Express arp request
2: Express arp The reply
3: Express rarp request
4: Express rarp The reply
Next , Let's take a look at the same broadcast domain ping message :
our host2 Want to go ping host1, So the mainframe 1 It is necessary to encapsulate the layer-2 message , First host2 Will check your MAC Address table , See if there is host1 The address of , without ,host2 It will send out ARP Broadcast packet
ARP The format of frame message is as follows :( omitted arp Hardware type of message , Upper protocol type ,MAC Address length ,IP Address length )
| Purpose MAC | Source MAC | The frame type | op | sender MAC | sender IP | The goal is MAC | The goal is IP |
|---|---|---|---|---|---|---|---|
| FF-FF-FF-FF-FF-FF | 52-54-00-00-11-22 | 0806 | 1 | 52-54-00-00-11-22 | 192.168.1.2 | 00-00-00-00-00-00 | 192.168.1.1 |
First , After our switch receives the message , Will inquire about the switch MAC Address table ( With learning function ), If there is host1 Of MAC Address , Direct return to host2; without , The switch will send to all ports ARP radio broadcast , After the host on other ports is found , If the goal is not yourself , Will discard the message ; until host1 After the host receives the message , Will respond host1 Of MAC What's the address , At the same time, learn the host host2 Of MAC Address , And follow the same format ARP The message is returned to host2.
host1 Back to ARP Frame message :
| Purpose MAC | Source MAC | The frame type | op | sender MAC | sender IP | The goal is MAC | The goal is IP |
|---|---|---|---|---|---|---|---|
| 52-54-00-00-11-22 | 52-54-00-00-11-11 | 0806 | 2 | 52-54-00-00-11-11 | 192.168.1.1 | 52-54-00-00-11-22 | 192.168.1.2 |
This is the time , host host2 I've learned that host1 Of MAC Address , So send icmp message
| Destination address | source address | … | Source IP | The goal is IP | … | ICMP message |
|---|---|---|---|---|---|---|
| 52-54-00-00-11-11 | 52-54-00-00-11-22 | 192.168.1.2 | 192.168.1.1 | Echo Request |
host1 After receiving the message , Hui Fu
| Destination address | source address | … | Source IP | The goal is IP | … | ICMP message |
|---|---|---|---|---|---|---|
| 52-54-00-00-11-22 | 52-54-00-00-11-11 | 192.168.1.1 | 192.168.1.2 | Echo Answer |
Next , Let's take a look at the differences between different broadcast domains ping
First of all, ensure that the whole network can reach !!!
If our host2 Still want to ping host ,host2 You have to go to the gateway to forward , But if you say , What if it doesn't know the gateway ? It will look like ping host1 like that , Send... First ARP message , Determine the gateway mac And then send icmp Send the message to the router .
We omit arp message
host2 send out ICMP Message to gateway
| Destination address | source address | … | Source IP | The goal is IP | … | ICMP message |
|---|---|---|---|---|---|---|
| 52-54-00-00-11-33 | 52-54-00-00-11-22 | 192.168.1.2 | 192.168.2.1 | Echo Request |
When the router receives a message from host2 Of icmp After the message , Find the destination address IP by 192.168.2.1, Query route discovery , We have to find an interface to go out , So get rid of the original mac Address header , Add your own mac Address header and to host3 forward ,( If there is no gateway host3 Of mac, Also have to send ARP Message inquiry , And the port of the router can also learn from the host mac Address , host host3 Can also learn router MAC Address ), The specific message is as follows :
| Destination address | source address | … | Source IP | The goal is IP | … | ICMP message |
|---|---|---|---|---|---|---|
| 52-54-00-00-11-55 | 52-54-00-00-11-44 | 192.168.1.2 | 192.168.2.1 | Echo Request |
host host3 I have learned about routers mac, This will return icmp message
| Destination address | source address | … | Source IP | The goal is IP | … | ICMP message |
|---|---|---|---|---|---|---|
| 52-54-00-00-11-44 | 52-54-00-00-11-55 | 192.168.2.1 | 192.168.1.2 | Echo Answer |
边栏推荐
- Shallow reading of reentrantlock source code of abstractqueuedsynchronizer (AQS)
- Floating point multiplication and division of vivado IP core floating point
- Shallow reading of condition object source code
- 非常实用的 Shell 和 shellcheck
- Leetcode question brushing record
- Hongke white paper | how to use TSN time sensitive network technology to build a digital factory in industry 4.0?
- The performance and viewing methods of websites attacked by DDoS
- ping 原理
- 4、 LAN and man
- What if the 80443 port of the website server has been maliciously attacked?
猜你喜欢
随机推荐
Embedding understanding + code
day02_基本语法
数据单位:位、字节、字、字长
The difference between DDoS attack and CC attack
Six common ways for hackers to attack servers
循环神经网络RNN
Hongke share | let you have a comprehensive understanding of "can bus errors" (IV) -- producing and recording can errors in practice
7、 Next generation Internet IPv6
Instruction rearrangement under multithreading concurrency
JMM memory model concept
MySQL 事物四种隔离级别分析
finally 和 return 的执行顺序
C语言内存-栈与堆使用
The performance and viewing methods of websites attacked by DDoS
day03_ 1_ Process control
find命令详解(文章最后运维最常用操作)
CNN convolutional neural network
STP spanning tree principle and example of election rules
What is WAF protection
CNAME记录和A记录的区别









