• [Linux系统] (5)系统网络


    一、路由表

    路由表是如何决策的:

    [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百度的时候:

    [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.38

    路由表是如何决策该怎么走:

    1)将14.215.177.38和每一条路由表的mask做按位与操作,确定要到达哪个网络。

    2)将与操作的结果与Destination匹配

    3)匹配上的,就将数据包从该条路由对应的端口发出去,目的MAC地址为网关。

    例如14.215.177.38只有与0.0.0.0按位与得到0.0.0.0,与Dest的0.0.0.0能匹配上。所以交给对应的Iface:eth0。

    Destination为0.0.0.0的路由项也叫默认路由,默认网关。

    二、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地址。

    三、mtr工具

    mtr工具用于跟踪某个ip的途径路由信息,类似traceroute:

    yum install mtr -y
    mtr 104.192.80.196
                                                                    My traceroute  [v0.85]
    centos7-test (0.0.0.0)                                                                                                       Thu Apr 16 23:02:00 2020
    Resolver: Received error response 2. (server failure)n. of fields   quit
                                                                                                                 Packets               Pings
     Host                                                                                                      Loss%   Snt   Last   Avg  Best  Wrst StDev
     1. 192.168.4.1                                                                                             0.0%     8    0.8   0.7   0.6   0.8   0.0
     2. 192.168.1.1                                                                                             0.0%     8    0.9   0.9   0.8   1.1   0.0
     3. 100.64.0.1                                                                                              0.0%     8    2.4  12.8   2.4  49.2  16.0
     4. 220.167.87.201                                                                                         85.7%     8    3.9   3.9   3.9   3.9   0.0
     5. 171.208.203.93                                                                                          0.0%     8    5.3  11.5   3.4  53.9  17.2
     6. 59.43.80.61                                                                                             0.0%     8    6.1   8.8   3.5  30.4   8.8
     7. ???
     8. 59.43.130.202                                                                                          62.5%     8   35.7  35.7  35.6  35.8   0.0
     9. 59.43.186.246                                                                                           0.0%     7   50.5  53.8  49.7  65.9   6.2
    10. 59.43.182.141                                                                                          28.6%     7  185.3 185.3 184.9 185.8   0.0
    11. 218.30.49.74                                                                                            0.0%     7  185.0 185.4 184.9 186.2   0.0
    12. 10.255.255.116                                                                                          0.0%     7  180.1 179.8 179.2 180.8   0.4
    13. 10.255.255.177                                                                                          0.0%     7  179.7 180.2 179.7 180.8   0.0
    14. 10.255.254.9                                                                                            0.0%     7  182.3 180.6 179.8 182.3   0.7
    15. 104.192.80.196                                                                                          0.0%     7  176.1 176.2 175.7 176.9   0.0

    这个结果会每隔一秒刷新一次,是一个持续不断的过程。而traceroute只会跟踪一次。

    附带traceroute工具的安装和使用:

    yum install traceroute -y
    traceroute 104.192.80.196

    ===

    保持学习,否则迟早要被淘汰*(^ 。 ^ )***
  • 相关阅读:
    Jenkins持续集成
    爬豆瓣保存到sqlite3
    爬豆瓣保存到Excel
    sqlite3数据库的增删查改
    用pandas和matplotlib对用户消费行为分析
    TCP请求
    fastjson
    断言
    将结果写入文件
    加解密
  • 原文地址:https://www.cnblogs.com/leokale-zz/p/11764612.html
Copyright © 2020-2023  润新知