抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >


数据转发过程

数据的封装和解封装

传输层

设备使用传输层协议进行报文封装,填充源端口和目的端口,标识位,序列号等等,之后交给网络层协议进行后续的封装.

网络层

在网络层进行封装时,要明确 IP 报文的源 IP 地址和目的 IP 地址,并通过协议标识上一层协议,封装完成后交给数据链路层进行封装.

数据链路层

    1. 如果访问的是同一网段的设备,目的 MAC 不需要填写成网关设备的 MAC 地址,ARP 会直接请求目的 IP 设备的 MAC 地址.
    1. 如果访问的是其他网段的设备,则需要通过网关转发出去,那么就要获取到网关的 MAC 地址.

    1. 首先查看 ARP 缓存表,如果表中记录着对应的 IP 地址和 MAC 地址的映射关系,则直接进行二层封装.
    1. 如果没有对应的信息,则通过 ARP 协议获取设备的 MAC 地址对二层进行封装,填写源目 MAC, Type 字段完成后,进行 FCS 检验填写.

物理层

在数据帧前添加前导码以及定界符,再通过 bit 流的形式在物理链路上进行传输.

解封装

当设备收到一个数据帧时,首先查看 FCS 字段,检验数据帧是否完整,之后再查看目的 MAC 地址,查看数据帧是不是给自己的.

再看 IP 头部中的目的 IP 地址,通过路由表查询去往该目的地的地址是否有对应的信息。如果有对应的信息,重新封装一个二层的头部和尾部.

到达最终的目的地时,接收方会先检查 FCS 检查数据是否完整,查看目的 MAC, 如果封装的是本设备的 MAC 地址,通过 type 字段交给上层协议进行处理.

然后查看目的 IP 是否为本设备的 IP 地址,如果是,通过 Protocol 字段,将数据交给上层协议进行处理.

TCP/UDP 协议通过目的端口判断,发送方想要访问本设备的哪种应用服务,然后交给服务进行处理.

数据转发原理

  1. 需要先进行域名解析

向 DNS 服务器发送域名查询信息进行解析 baidu.com 对应的 IP 地址.

DNS 服务器回应请求消息,将百度服务器的 IP 地址告知 PC.

DNS
114 114.114.114.114
阿里 223.5.5.5
百度
360DNS
谷歌 8.8.8.8
  1. 开始封装,在封装数据链路层时,发现目的 IP 与源 IP 不在同一网络中,这时通过 ARP 请求网关的 MAC 地址,并进行封装

  2. 当数据经过交换机时,交换机根据 MAC 地址表进行转发,交给网关处理.

  3. 网关收到数据帧后,进行解封装,查看 MAC 地址为自己的 MAC 地址,继续解封装,发现目的 IP 地址并不是自己的 IP 地址,需要根据路由表重新封装数据帧并转发.

  4. 服务器在收到消息后解封装处理,最终将数据交给对应的应用服务.

数据转发原理

AR1
<Huawei>sy    
<Huawei>system-view
Enter system view, return user view with Ctrl+Z.
[Huawei]sy
[Huawei]sysname R1
[R1]int
[R1]interface g0/0/0
[R1-GigabitEthernet0/0/0]ip add
[R1-GigabitEthernet0/0/0]ip address 192.168.1.254 ?
INTEGER<0-32> Length of IP address mask
IP_ADDR<X.X.X.X> IP address mask
[R1-GigabitEthernet0/0/0]ip address 192.168.1.254 24
Dec 18 2023 15:34:43-08:00 R1 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP
on the interface GigabitEthernet0/0/0 has entered the UP state.
[R1-GigabitEthernet0/0/0]
[R1-GigabitEthernet0/0/0]
[R1-GigabitEthernet0/0/0]interface g0/0/1
[R1-GigabitEthernet0/0/1]
[R1-GigabitEthernet0/0/1]ip address 10.1.1.254 24
Dec 18 2023 15:36:09-08:00 R1 %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP
on the interface GigabitEthernet0/0/1 has entered the UP state.
[R1-GigabitEthernet0/0/1]
[R1-GigabitEthernet0/0/1]
[R1-GigabitEthernet0/0/1]
[R1-GigabitEthernet0/0/1]q
[R1]q
<R1>sa
<R1>save
The current configuration will be written to the device.
Are you sure to continue? (y/n)[n]:y
It will take several minutes to save configuration file, please wait.......
Configuration file had been saved successfully
Note: The configuration file will take effect after being activated
<R1>
<R1>
<R1>
<R1>sy
Enter system view, return user view with Ctrl+Z.
[R1]dis
[R1]display inter
[R1]display interface g0/0/0
GigabitEthernet0/0/0 current state : UP
Line protocol current state : UP
Last line protocol up time : 2023-12-18 15:34:43 UTC-08:00
Description:HUAWEI, AR Series, GigabitEthernet0/0/0 Interface
Route Port,The Maximum Transmit Unit is 1500
Internet Address is 192.168.1.254/24
IP Sending Frames' Format is PKTFMT_ETHNT_2, Hardware address is 00e0-fc7d-4606
Last physical up time : 2023-12-18 15:21:06 UTC-08:00
Last physical down time : 2023-12-18 15:20:59 UTC-08:00
Current system time: 2023-12-18 15:40:47-08:00
Port Mode: FORCE COPPER
Speed : 1000, Loopback: NONE
Duplex: FULL, Negotiation: ENABLE
Mdi : AUTO
Last 300 seconds input rate 456 bits/sec, 0 packets/sec
Last 300 seconds output rate 16 bits/sec, 0 packets/sec
Input peak rate 1040 bits/sec,Record time: 2023-12-18 15:39:01
Output peak rate 472 bits/sec,Record time: 2023-12-18 15:39:01

Input: 562 packets, 65813 bytes
Unicast: 16, Multicast: 541
Broadcast: 5, Jumbo: 0
Discard: 0, Total Error: 0

CRC: 0, Giants: 0
Jabbers: 0, Throttles: 0
Runts: 0, Symbols: 0
Ignoreds: 0, Frames: 0

Output: 17 packets, 1216 bytes
Unicast: 15, Multicast: 0
Broadcast: 2, Jumbo: 0
Discard: 0, Total Error: 0

Collisions: 0, ExcessiveCollisions: 0
Late Collisions: 0, Deferreds: 0

Input bandwidth utilization threshold : 100.00%
Output bandwidth utilization threshold: 100.00%
Input bandwidth utilization : 0%
Output bandwidth utilization : 0%

[R1]
[R1]
[R1]display interface g0/0/1
GigabitEthernet0/0/1 current state : UP
Line protocol current state : UP
Last line protocol up time : 2023-12-18 15:36:09 UTC-08:00
Description:HUAWEI, AR Series, GigabitEthernet0/0/1 Interface
Route Port,The Maximum Transmit Unit is 1500
Internet Address is 10.1.1.254/24
IP Sending Frames' Format is PKTFMT_ETHNT_2, Hardware address is 00e0-fc7d-4607
Last physical up time : 2023-12-18 15:21:06 UTC-08:00
Last physical down time : 2023-12-18 15:20:59 UTC-08:00
Current system time: 2023-12-18 15:42:10-08:00
Port Mode: COMMON COPPER
Speed : 1000, Loopback: NONE
Duplex: FULL, Negotiation: ENABLE
Mdi : AUTO
Last 300 seconds input rate 16 bits/sec, 0 packets/sec
Last 300 seconds output rate 16 bits/sec, 0 packets/sec
Input peak rate 472 bits/sec,Record time: 2023-12-18 15:39:01
Output peak rate 472 bits/sec,Record time: 2023-12-18 15:39:01

Input: 12 packets, 810 bytes
Unicast: 10, Multicast: 0
Broadcast: 2, Jumbo: 0
Discard: 0, Total Error: 0

CRC: 0, Giants: 0
Jabbers: 0, Throttles: 0
Runts: 0, Symbols: 0
Ignoreds: 0, Frames: 0

Output: 11 packets, 786 bytes
Unicast: 9, Multicast: 0
Broadcast: 2, Jumbo: 0
Discard: 0, Total Error: 0

Collisions: 0, ExcessiveCollisions: 0
Late Collisions: 0, Deferreds: 0

Input bandwidth utilization threshold : 100.00%
Output bandwidth utilization threshold: 100.00%
Input bandwidth utilization : 0%
Output bandwidth utilization : 0%

[R1]
[R1]
[R1]

推荐阅读
DHCP DHCP IP路由基础 IP路由基础 交换网络基础 交换网络基础 ARP协议 ARP协议 远程登录 远程登录 以太网链路聚合 以太网链路聚合

留言区

Are You A Robot?