1、路由表centos
路由表是如何决策的:服务器
[root@centos-clone1 ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
能够看到路由表中的条目:网络
当咱们ping百度的时候:spa
[root@centos-clone1 ~]# ping www.baidu.com PING www.a.shifen.com (14.215.177.38) 56(84) bytes of data. 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=1 ttl=55 time=35.0 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=2 ttl=55 time=33.4 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=3 ttl=55 time=33.7 ms
首先会经过DNS服务器解析baidu的IP地址为:14.215.177.38code
路由表是如何决策该怎么走:blog
1)将14.215.177.38和每一条路由表的mask作按位与操做,肯定要到达哪一个网络。路由
2)将与操做的结果与Destination匹配io
3)匹配上的,就将数据包从该条路由对应的端口发出去,目的MAC地址为网关。table
例如14.215.177.38只有与0.0.0.0按位与获得0.0.0.0,与Dest的0.0.0.0能匹配上。因此交给对应的Iface:eth0。class
Destination为0.0.0.0的路由项也叫默认路由,默认网关。
2、ARP表(MAC表)
[root@centos-clone1 ~]# arp -a ? (192.168.1.1) at e8:ab:f3:e2:f0:49 [ether] on eth0 ? (192.168.1.8) at bc:ae:c5:1a:dd:96 [ether] on eth0
咱们看192.168.1.1这条,这个IP地址是默认网关的地址。
当一个数据包查找路由表后,须要将该包发给默认网关,则须要查找默认网关的MAC地址。
在ARP中查找到第一条,默认网关的MAC地址是:e8:ab:f3:e2:f0:49,则该数据包二层信息中的目的MAC地址填写该MAC地址。