当前位置:网站首页>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
边栏推荐
- Data7202 statistical analysis
- ARM processor operating mode
- Handling skills of SQL optimization (2)
- Netstat command – displays network status
- Getting started with Silverlight development 1
- Mongodb delete data
- ctfshow-misc
- Go quiz: considerations for function naming return value from the go interview question (more than 80% of people answered wrong)
- At the age of 26, I was transferred to software testing with zero foundation. Now I have successfully entered the job with a monthly salary of 12K. However, no one understands my bitterness
- Invalid bound statement (not found)
猜你喜欢

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

Day21 JMeter usage basis

CTFSHOW
Summary of 6 common methods of visual deep learning model architecture

Processes and threads - concepts and process scheduling

What is the slice flag bit
![[network security] sharing of experience and ideas of an emergency battle](/img/9b/dd6e47ad7610eefd2b8c93602d6a7e.jpg)
[network security] sharing of experience and ideas of an emergency battle
![[short time average zero crossing rate] short time average zero crossing rate of speech signal based on MATLAB [including Matlab source code 1721]](/img/4a/304f262c1c08800aa95f9e2d537e4d.jpg)
[short time average zero crossing rate] short time average zero crossing rate of speech signal based on MATLAB [including Matlab source code 1721]

Getting started with Silverlight development 1

What is the IP address
随机推荐
Laravel8+ wechat applet generates QR code
Cnpm installation
JD 8 fleet stores search history, deletes history, clears history (not finished)
Wind farm visualization: wind farm data
Detailed explanation of @jsoninclude annotation in Jackson
Understand what ICMP Protocol is
Wechat applet simply realizes chat room function
Lesson 8: FTP server setup and loading
An interview question record about where in MySQL
Lesson 9: workspace introduction
What elements are indispensable for the development of the character? What are the stages
ARM processor operating mode
Wechat applet authorization login + mobile phone sending verification code +jwt verification interface (laravel8+php)
Mount command - file system mount
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
Day21 performance test process
MV command – move or rename files
Highway
Ifconfig command – displays or sets network devices
What are the reasons why most webmasters choose Hong Kong site group servers?