Centos Network is unreachable
问题
[root@server3 etc]# ping baidu.com
connect: Network is unreachable
OS版本
[root@server3 etc]# cat /proc/version
Linux version 2.6.32-754.2.1.el6.x86_64 (mockbuild@x86-01.bsys.centos.org) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC) ) #1 SMP Fri Jul 13 12:50:12 UTC 2018
Ping 网关
[root@server3 etc]# ping 10.84.209.1
PING 10.84.209.1 (10.84.209.1) 56(84) bytes of data.
64 bytes from 10.84.209.1: icmp_seq=1 ttl=64 time=1.34 ms
64 bytes from 10.84.209.1: icmp_seq=2 ttl=64 time=1.39 ms
64 bytes from 10.84.209.1: icmp_seq=3 ttl=64 time=1.34 ms
64 bytes from 10.84.209.1: icmp_seq=4 ttl=64 time=1.36 ms
64 bytes from 10.84.209.1: icmp_seq=5 ttl=64 time=1.35 ms
64 bytes from 10.84.209.1: icmp_seq=6 ttl=64 time=1.34 ms
64 bytes from 10.84.209.1: icmp_seq=7 ttl=64 time=1.34 ms
64 bytes from 10.84.209.1: icmp_seq=8 ttl=64 time=1.35 ms
64 bytes from 10.84.209.1: icmp_seq=9 ttl=64 time=1.38 ms
64 bytes from 10.84.209.1: icmp_seq=10 ttl=64 time=1.43 ms
^C
--- 10.84.209.1 ping statistics ---
10 packets transmitted, 10 received, 0% packet loss, time 9573ms
rtt min/avg/max/mdev = 1.340/1.367/1.438/0.044 ms
ping网关和同网段内IP正常,这里导致重试了好多方法,就是没有想到网关设置问题。
DNS
[root@server3 etc]# cat resolv.conf
; generated by /sbin/dhclient-script
nameserver 10.84.209.8
nameserver 114.114.114.114
[root@server3 etc]# nslookup
> baidu.com
Server: 10.84.209.8
Address: 10.84.209.8#53
Non-authoritative answer:
Name: baidu.com
Address: 39.156.69.79
Name: baidu.com
Address: 220.181.38.148
> exit
DNS解析正常,但注意DNS服务器其实是内网的。
检查路由表
[root@server3 etc]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.84.209.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth1
OK,最后发现网关呢。。。
检查网卡配置
[root@server3 etc]# vi /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
TYPE=Ethernet
UUID=3a9503c6-ce00-400a-8ec1-dc445b845237
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
HWADDR=00:0c:29:4d:a3:91
DEFROUTE=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth1"
IPADDR=10.84.209.228
NETMASK=255.255.255.0
DNS2=114.114.114.114
GATEWAY=10.84.214.1
DNS1=10.84.209.8
USERCTL=no
问题出在 GATEWAY= 10.84.214.1 \color{red}{10.84.214.1} 10.84.214.1,改回GATEWAY=10.84.209.1
OK,可以继续愉快的玩耍了
[root@server3 etc]# ping baidu.com
PING baidu.com (39.156.69.79) 56(84) bytes of data.
64 bytes from 39.156.69.79: icmp_seq=1 ttl=44 time=59.0 ms
64 bytes from 39.156.69.79: icmp_seq=2 ttl=44 time=56.6 ms
64 bytes from 39.156.69.79: icmp_seq=3 ttl=44 time=57.2 ms
64 bytes from 39.156.69.79: icmp_seq=4 ttl=44 time=56.8 ms
64 bytes from 39.156.69.79: icmp_seq=5 ttl=44 time=57.4 ms
64 bytes from 39.156.69.79: icmp_seq=6 ttl=44 time=57.0 ms
64 bytes from 39.156.69.79: icmp_seq=7 ttl=44 time=56.9 ms
64 bytes from 39.156.69.79: icmp_seq=8 ttl=44 time=56.6 ms
64 bytes from 39.156.69.79: icmp_seq=9 ttl=44 time=56.9 ms
64 bytes from 39.156.69.79: icmp_seq=10 ttl=44 time=57.8 ms
64 bytes from 39.156.69.79: icmp_seq=11 ttl=44 time=57.2 ms
64 bytes from 39.156.69.79: icmp_seq=12 ttl=44 time=56.6 ms
^C
--- baidu.com ping statistics ---
12 packets transmitted, 12 received, 0% packet loss, time 11142ms
rtt min/avg/max/mdev = 56.600/57.199/59.018/0.716 ms
总结
处理网络问题,一般先用ping命令测试网络是否通。
- 测试本地地址 lo 网卡
ping 127.0.0.1 - 测试本地局域网地址,通常使用网关ip
ping 10.84.209.1 - 测试外网地址,个人通常使用baidu.com
这个阶段就会检查到DNS,路由,防火墙等。