Linux ping:unknown host问题排查

一、检查网卡配置:
输入ifconfig可以查看当前网卡配置的IP地址并且查看配置文件中网络的设置:

[root@bqh-01 ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:71:FC:1E  
          inet addr:192.168.0.117  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe71:fc1e/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:675 errors:0 dropped:0 overruns:0 frame:0
          TX packets:357 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:53393 (52.1 KiB)  TX bytes:31943 (31.1 KiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

[root@bqh-01 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0   #若没有,手动添加即可
DEVICE=eth0
HWADDR=00:0C:29:71:FC:1E
TYPE=Ethernet
UUID=d1518dbb-7e56-46f3-94e4-f59927222526
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.0.117
NETMASK=255.255.255.0
GATEWAY=192.168.0.1

二、检查网卡网关设置:

[root@bqh-01 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
0.0.0.0         192.168.0.1     0.0.0.0         UG    0      0        0 eth0
[root@bqh-01 ~]# ping 192.168.0.1
PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.
64 bytes from 192.168.0.1: icmp_seq=1 ttl=64 time=1.51 ms
64 bytes from 192.168.0.1: icmp_seq=2 ttl=64 time=1.03 ms
64 bytes from 192.168.0.1: icmp_seq=3 ttl=64 time=0.961 ms

如果未设置,则通过如下方式增加网关:route add default gw 192.168.0.1

三、查看系统默认的网关(如果没有,可以vim手动添加一个上去)

[root@bqh-01 ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=bqh-01
[root@bqh-01 ~]# echo "GATEWAY=192.168.0.1" >>/etc/sysconfig/network
[root@bqh-01 ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=bqh-01
GATEWAY=192.168.0.1
[root@bqh-01 ~]# ping baidu.com
^C

四、检查DNS设置:

出现 ping:unknown host 提示大部分原因是 linux 设置的DNS解析不了

[root@bqh-01 ~]# cat /etc/resolv.conf 
nameserver 192.168.43.1
[root@bqh-01 ~]# sed -i s#43#0#g /etc/resolv.conf 
[root@bqh-01 ~]# cat /etc/resolv.conf 
nameserver 192.168.0.1
[root@bqh-01 ~]# ping www.baidu.com
PING www.a.shifen.com (220.181.38.150) 56(84) bytes of data.
64 bytes from 220.181.38.150: icmp_seq=1 ttl=53 time=14.3 ms
64 bytes from 220.181.38.150: icmp_seq=2 ttl=53 time=14.4 ms
^C
--- www.a.shifen.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1072ms
rtt min/avg/max/mdev = 14.323/14.403/14.483/0.080 ms

建议域名服务器设置Google的公共DNS服务

posted @ 2019-08-10 23:16  南清风  阅读(1404)  评论(0编辑  收藏  举报