当前位置:网站首页>How two hosts in different network segments directly connected communicate
How two hosts in different network segments directly connected communicate
2022-06-25 06:23:00 【Programmer community】
Let's take a look today , How to make two directly connected hosts , Configure different network segments ip After the address , just so so ping through . And what can we learn from it ?
Environment configuration
Prepare two computers , System is Ubuntu Of , Connect their network interfaces with a cable
stay Ubuntu Configure their ip Address :
- A Host's local network card eth0 To configure 192.168.1.100/24
- B Host's local network card eth0 To configure 192.168.3.100/24
open B The host wireshark Caught tools , On the local network card eth0 Upper grab bag
Execution steps
First of all, use it under the terminal ifconfig Configure two hosts ip After the address , stay A In the terminal window of the host computer ping B The host ip Address 192.168.3.100, Found that there was no ping through ,A The terminal of the host displays :connect:Network is unreachable
We know :
A Want to send icmp request , First icmp The request message must be a complete message
What is missing in the message sent ?
Purpose MAC Address
therefore A You have to broadcast first ARP request , however B Didn't receive ARP request
A and B It's directly connected , And they don't have routers to isolate broadcast packets , Why? B There's no broadcast ARP What about the request ?
AB Direct connection , There should be no possibility of losing it in the middle of the way ,B I didn't get it again , So there's only one possibility ,A Of ARP It didn't go out at all , Why didn't you send it out ?
Because it didn't find the way to go , It doesn't know the purpose ip by 192.168.3.100 Which network interface should the message be sent from
Why don't you know ? Because it doesn't find a matching routing rule in the routing table . That's why A The host will show :connect:Network is unreachable Why
So the second step
stay A Add a routing rule to the routing table of , issue 192.168.3.0/24 All messages of the network segment should be sent from the network card eth0 Send it out , In this way, a complete message can be sent out from the specified network interface
Execute again at this time ping operation ,A Because I don't know B Of MAC Address , It's going to be broadcast first ARP request
radio broadcast ARP Is the request complete ? Yes
Why? ?
Because of the purpose MAC There are addresses , radio broadcast MAC Address
If you want to send a complete message , To find a matching rule in the routing table , Send it to the purpose ip 192.168.3.100 Can I match the message of ?
Tolerable , Because a rule was added in the previous step , All to 192.168.3.0/24 The message of network segment is sent from network card eth0 Send it out , So the radio ARP The message can be sent out
The hair is sent out , That can reach B The mainframe ?
Because it's direct connection , Certainly.
Just imagine , If A and B It's a router connection , Can reach B Do you ? Definitely not , Why? ? Because routers cut off broadcast messages
host B received A Broadcast of ARP Request message , But there was no reply ARP Respond to , Why? ?
And before A The mainframe can't send out ARP Request the same ,B Want to send ARP Respond to , But no routing rules are found in the routing table , Go to 192.168.1.0/24 Routing rules of network segment
So step four
B The host also needs to add a routing rule , issue 192.168.1.0/24 All messages of the network segment should be sent from the network card eth0 Send it out , In this way, a complete message can be sent out from the specified network interface
here A Host again ping B host , Discovery can ping Through the ,B Grab the package on the host and you can see , First A From the mainframe ARP request ,B host ARP The protocol layer automatically replied ARP Respond to , next A Again icmp request ,B The host icmp The protocol layer replies automatically again icmp Respond to
thus ,A and B Of ip Although the address is different, the network segment , But directly connected, they can still communicate
Let's think about another question :
If the two directly connected hosts ip The address is the same as the network segment , Sure ping through , There is no doubt about it , But there is no manual addition of routing rules , Why can ping through ?
That's because when your host network card is configured ip Address time , The system will automatically put “ This ip And this network card ” Added to the routing table as a rule
summary
If you want to send a message , It must be ensured that the message is complete , That is to say, its source ip、 Source mac、 Purpose ip、 Purpose mac There has to be , And then according to its purpose ip Match routing table , Determine which network card to send , With these , The message will be sent out from the network card
Messages sent out , How to accurately send to the destination host , It's decided by the switches and routers on the network
The broadcast domain of a broadcast message , It does not refer to all hosts in the same network segment as the source host , But as long as there's no router , Can be sent to all other hosts connected to the area , Broadcast domain and ip The address is irrelevant
边栏推荐
- Rational investment and internationalism
- What does cardinality mean in set
- Aviator an expression evaluation engine
- MySQL tuning -- 02 -- slow query log
- Kotlin reflection -- Notes
- Lesson 9: workspace introduction
- BGP - basic concept
- The sum problem
- An interview question record about where in MySQL
- Summary of 6 common methods of visual deep learning model architecture
猜你喜欢
[interview with a large factory] meituan had two meetings. Was there a surprise in the end?
No one reads the series. Source code analysis of copyonwritearraylist
What happens when redis runs out of memory
Tencent and China Mobile continued to buy back with large sums of money, and the leading Hong Kong stocks "led" the market to rebound?
Add the author watermark plugin v1.4 update to the posts of elegant grass discuz plugin - some forums post errors and bugs have been fixed
IQ debugging of Hisilicon platform ISP and image (1)
@Detailed explanation of valid annotation usage
MySQL tuning --01--- optimization steps and system performance parameters
How to use asemi FET 7n80 and how to use 7n80
Laravel8 fill data
随机推荐
You can't specify target table for update in from clause error in MySQL
Investment opportunities and operational risk assessment report of China's engineering consulting industry during the 14th Five Year Plan period 2022-2028
Analysis report on investment and financing status and operation benefits of global and Chinese dental industry (2022 Edition)
Find command – find and search for files
[open source sharing] deeply study KVM, CEPH, fuse features, including open source projects, code cases, articles, videos, architecture brain maps, etc
Optimal Parking
An interview question record about where in MySQL
Processes and threads - concepts and process scheduling
cacacahe
Echo command – output a string or extract the value of a shell variable
Tail command – view the contents at the end of the file
[short time energy] short time energy of speech signal based on MATLAB [including Matlab source code 1719]
Notes on dashboard & kuboard installation in kubernetes cluster
RM command – remove file or directory
RT thread i/o device model and layering
Handling skills of SQL optimization (2)
Day21 JMeter usage basis
Analysis report on production and sales demand and sales prospect of global and Chinese phosphating solution Market 2022-2028
Research Report on demand and Competitive Prospect of global and Chinese welding personal protective equipment industry 2022-2027
证券如何在线开户?在线开户是安全么?