当前位置:网站首页>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
边栏推荐
- Research Report on marketing channel analysis and competitive strategy of China's polycarbonate industry 2022
- Report on strategic suggestions on investment direction and Prospect of global and Chinese marine biological industry (2022 Edition)
- VMware virtual machine prompt: the virtual device ide1:0 cannot be connected because there is no corresponding device on the host.
- Understand what MTU is
- Mongodb delete data
- Global and Chinese medical protective clothing market supply and demand research and investment value proposal report 2022-2028
- Optimal Parking
- [road of system analyst] collection of wrong questions in the chapters of Applied Mathematics and economic management
- CTFSHOW
- Go uses channel to control concurrency
猜你喜欢

Invalid bound statement (not found)

What elements are indispensable for the development of the character? What are the stages

Mongodb basic concept learning - set

Tencent and China Mobile continued to buy back with large sums of money, and the leading Hong Kong stocks "led" the market to rebound?

Rhcsa--- day 6 operation

Asemi fast recovery diode us1m parameters, us1m recovery time, us1m voltage drop

What is the IP address

Face++ realizes face detection by flow
![[Suanli network] problems and challenges faced by the development of Suanli network](/img/90/1d537de057113e2b4754e76746f256.jpg)
[Suanli network] problems and challenges faced by the development of Suanli network

Notes on dashboard & kuboard installation in kubernetes cluster
随机推荐
Arm instructions and others
Uname command – displays system information
The sum problem
Linus' speech recordings, which were lost in 1994, were made public
MySQL tuning --01--- optimization steps and system performance parameters
Count the grid
Netstat command – displays network status
Day21 performance test process
General test point ideas are summarized and shared, which can be directly used in interview and actual software testing
Rhcsa day 4
Research Report on global and Chinese vaccine market profit forecast and the 14th five year plan development strategy 2022-2028
Wind farm visualization: wind farm data
Mongodb basic concept learning - set
Es11 new methods: dynamic import(), bigint, globalthis, optional chain, and null value merging operator
IQ debugging of Hisilicon platform ISP and image (1)
Global and Chinese benzoic acid market competition strategy and demand scale forecast report 2022
Methods for obtaining some information of equipment
Go uses channel to control concurrency
[Suanli network] technological innovation of Suanli Network -- Key Technologies of green and security
Day21 JMeter usage basis