解决'服务器无法连接外网'问题的过程记录


问题描述

最近几天发现实验室的服务器无法连接外网,ping不通,无法git clone代码等等。每天花一点时间尝试排查一下问题出在哪里,看看怎么解决。

过程

  1. ifconfig 看一下信息。可以看到:平时ssh连接的网卡是ens192,它的内网IP是172.17.172.192,运行状态好像没什么问题;ens160的内网IP是169.254.8.98,好像有问题,本地没办法ping通;

    $ ifconfig
    docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 172.18.0.1  netmask 255.255.0.0  broadcast 172.18.255.255
            inet6 fe80::42:50ff:fe64:4e73  prefixlen 64  scopeid 0x20<link>
            ether 02:42:50:64:4e:73  txqueuelen 0  (Ethernet)
            RX packets 178670  bytes 144916517 (144.9 MB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 3362197  bytes 340061285 (340.0 MB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet6 fc00:7934:ba68:1:453f:626d:245b:93e8  prefixlen 64  scopeid 0x0<global>
            inet6 fc00:7934:ba68:1:fa5b:3156:d9d2:37e0  prefixlen 64  scopeid 0x0<global>
            inet6 fc00:7934:ba68:1:4e07:d3e:9f21:eea4  prefixlen 64  scopeid 0x0<global>
            inet6 fc00:7934:ba68:1:6137:f06e:9597:d985  prefixlen 64  scopeid 0x0<global>
            inet6 fe80::c8b7:129e:b125:6a28  prefixlen 64  scopeid 0x20<link>
            inet6 fc00:7934:ba68:1:242d:4fe9:2c0c:cd2f  prefixlen 64  scopeid 0x0<global>
            inet6 fc00:7934:ba68:1:808c:f4a7:b0eb:bf63  prefixlen 64  scopeid 0x0<global>
            inet6 fc00:7934:ba68:1:6d60:5c0:d8e4:d9cb  prefixlen 64  scopeid 0x0<global>
            inet6 fc00:7934:ba68:1:a6b:d8f7:cf36:9130  prefixlen 64  scopeid 0x0<global>
            inet6 fc00:7934:ba68:1:f654:1fe0:9220:daa1  prefixlen 64  scopeid 0x0<global>
            ether 00:0c:29:80:36:ef  txqueuelen 1000  (Ethernet)
            RX packets 20356000  bytes 7320601513 (7.3 GB)
            RX errors 0  dropped 693  overruns 0  frame 0
            TX packets 25632830  bytes 3912930954 (3.9 GB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    ens192: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 172.17.172.192  netmask 255.255.248.0  broadcast 172.17.175.255
            inet6 2001:250:6803:206:8ec4:af17:22a0:204c  prefixlen 64  scopeid 0x0<global>
            inet6 2001:250:6803:206:1b61:1818:9181:3833  prefixlen 64  scopeid 0x0<global>
            inet6 2001:250:6803:206:8b33:c189:6e29:a038  prefixlen 64  scopeid 0x0<global>
            inet6 2001:250:6803:206:2381:b202:cd4d:c781  prefixlen 64  scopeid 0x0<global>
            inet6 2001:250:6803:206:81ad:159d:f8bb:6893  prefixlen 64  scopeid 0x0<global>
            inet6 2001:250:6803:206:5a18:1bd3:8525:f532  prefixlen 64  scopeid 0x0<global>
            inet6 2001:250:6803:206:744f:830a:46fd:2cc9  prefixlen 64  scopeid 0x0<global>
            inet6 2001:250:6803:206:cf03:ab8a:585:5810  prefixlen 64  scopeid 0x0<global>
            inet6 fe80::2f79:480e:1041:4000  prefixlen 64  scopeid 0x20<link>
            inet6 2001:250:6803:206:8a4a:e39e:ee42:d311  prefixlen 64  scopeid 0x0<global>
            ether 00:0c:29:80:36:f9  txqueuelen 1000  (Ethernet)
            RX packets 50603025  bytes 9110805500 (9.1 GB)
            RX errors 0  dropped 703  overruns 0  frame 0
            TX packets 29180189  bytes 18701212188 (18.7 GB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    ens160:avahi: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 169.254.8.98  netmask 255.255.0.0  broadcast 169.254.255.255
            ether 00:0c:29:80:36:ef  txqueuelen 1000  (Ethernet)
    
    lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
            inet 127.0.0.1  netmask 255.0.0.0
            inet6 ::1  prefixlen 128  scopeid 0x10<host>
            loop  txqueuelen 1000  (Local Loopback)
            RX packets 8260572  bytes 1759584719 (1.7 GB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 8260572  bytes 1759584719 (1.7 GB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    vethabaa764: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet6 fe80::f013:f5ff:fe7b:9d43  prefixlen 64  scopeid 0x20<link>
            ether f2:13:f5:7b:9d:43  txqueuelen 0  (Ethernet)
            RX packets 178663  bytes 147417543 (147.4 MB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 2162158  bytes 290116295 (290.1 MB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    zt44xh4rxy: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 2800
            inet 192.168.192.124  netmask 255.255.255.0  broadcast 192.168.192.255
            inet6 fe80::9465:3eff:fee1:a8cc  prefixlen 64  scopeid 0x20<link>
            ether 96:65:3e:e1:a8:cc  txqueuelen 1000  (Ethernet)
            RX packets 119243  bytes 13381700 (13.3 MB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 2653  bytes 229946 (229.9 KB)
            TX errors 0  dropped 6632 overruns 0  carrier 0  collisions 0
    
  2. route 看一下路由表。路由表好像有点问题,172.17.168.1是什么IP?

    $ route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    0.0.0.0         172.17.168.1    0.0.0.0         UG    0      0        0 ens192
    0.0.0.0         0.0.0.0         0.0.0.0         U     1002   0        0 ens160
    0.0.0.0         172.17.168.1    0.0.0.0         UG    20101  0        0 ens192
    169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 ens160
    172.17.168.0    0.0.0.0         255.255.248.0   U     101    0        0 ens192
    172.18.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
    192.168.192.0   0.0.0.0         255.255.255.0   U     0      0        0 zt44xh4rxy
  3. 先尝试把ens192的IP加到路由表里面。

    $ sudo route add -net 0.0.0.0 netmask 0.0.0.0 gw 172.17.172.1
    $ route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    0.0.0.0         172.17.172.1    0.0.0.0         UG    0      0        0 ens192
    0.0.0.0         172.17.168.1    0.0.0.0         UG    0      0        0 ens192
    0.0.0.0         0.0.0.0         0.0.0.0         U     1002   0        0 ens160
    0.0.0.0         172.17.168.1    0.0.0.0         UG    20101  0        0 ens192
    169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 ens160
    172.17.168.0    0.0.0.0         255.255.248.0   U     101    0        0 ens192
    172.18.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
    192.168.192.0   0.0.0.0         255.255.255.0   U     0      0        0 zt44xh4rxy
    $ ping www.baidu.com
    ping: www.baidu.com: Temporary failure in name resolution
  4. “Temporary failure in name resolution”,是不是DNS解析的问题?尝试修改DNS服务器配置。网上常见的教程就是修改/etc/resolv.conf,但是打开这个文件发现第一行就写着 “Do not edit.”

    # This file is managed by man:systemd-resolved(8). Do not edit.
    #
    # This is a dynamic resolv.conf file for connecting local clients to the
    # internal DNS stub resolver of systemd-resolved. This file lists all
    # configured search domains.
    #
    # Run "resolvectl status" to see details about the uplink DNS servers
    # currently in use.
    #
    # Third party programs must not access this file directly, but only through the
    # symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
    # replace this symlink by a static file or a different symlink.
    #
    # See man:systemd-resolved.service(8) for details about the supported modes of
    # operation for /etc/resolv.conf.
    
    nameserver 127.0.0.53
    options edns0 trust-ad
  5. 按照文件中的指示,resolvectl status

    ......
    Link 3 (ens192)
          Current Scopes: DNS            
    DefaultRoute setting: yes            
           LLMNR setting: yes            
    MulticastDNS setting: no             
      DNSOverTLS setting: no             
          DNSSEC setting: no             
        DNSSEC supported: no             
             DNS Servers: 210.34.48.59   
                          218.104.128.106
                          218.85.157.99  
              DNS Domain: ~.
    ......

    这3个DNS Server都ping不通啊。现在有点怀疑会不会真是没有网了。


文章作者: 李立基
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 李立基 !
  目录