解决 Linux ping: unknown host www.baidu.com报错

 1 "ping: unknown host www.baidu.com" 
 2 解决方案: 
 3    如果某台Linux服务器ping不通域名, 如下提示: 
 4 [root@localhost ~]# ping www.baidu.com
 5 ping: unknown host www.baidu.com
 6 
 7 首先确定已经连接上路由器,并且路由器能够访问外网,可以通过访问网关进行确定
 8 
 9 [root@localhost ~]# ping 192.168.1.1
10 PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
11 64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=2.96 ms
12 64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=1.75 ms
13 
14 如果确定网络没问题的情况下, 可以通过如下步骤寻找解决办法: 
15 1) 确定设置了域名服务器, 没有的话, 建议设置Google的公共DNS服务[nameserver 8.8.8.8], 它应该不会出问题的 
16 
17 [root@localhost ~]# cat /etc/resolv.conf
18 search localdomain
19 
20 因为我的DNS没有设置所以导致了ping外网ping不通。将dns添加到该文件中
21 
22 [root@localhost ~]# vi /etc/resolv.conf
23 
24 search localdomain
25 nameserver 202.98.96.68
26 nameserver 61.139.2.69
27 ~
28 2) 确保网关已设置 
29 
30 # grep GATEWAY /etc/sysconfig/network-scripts/ifcfg* 
31 ------------------------------------------------------------------- 
32 /etc/sysconfig/network-scripts/ifcfg-eth0:GATEWAY=192.168.40.1 
33 ------------------------------------------------------------------- 
34 
35 如果未设置, 则通过如下方式增加网关: 
36 
37 # route add default gw 192.168.40.1 
38 
39 或者手工编写/etc/sysconfig/network-scripts/ifcfg*文件后, 重启network服务: 
40 
41 # service network restart 
42 
43 3) 确保可用dns解析 
44 
45 # grep hosts /etc/nsswitch.conf 
46 ------------------------------------------------------------------- 
47 hosts:      files dns 
48 ------------------------------------------------------------------- 
49 
50 如果以上哪个有问题, 修正后, 再测试, 应该就没问题了: 
51 
52 #ping -c 3 www.baidu.com 
53 PING www.a.shifen.com (220.181.6.175) 56(84) bytes of data. 
54 64 bytes from 220.181.6.175: icmp_seq=0 ttl=50 time=9.51 ms 
55 64 bytes from 220.181.6.175: icmp_seq=1 ttl=50 time=8.45 ms 
56 64 bytes from 220.181.6.175: icmp_seq=2 ttl=50 time=8.97 ms 
57 --- www.a.shifen.com ping statistics --- 
58 3 packets transmitted, 3 received, 0% packet loss, time 2002ms 
59 rtt min/avg/max/mdev = 8.450/8.977/9.511/0.446 ms, pipe 2 

转载自:http://www.cnblogs.com/happyhotty/articles/2539951.html

猜你喜欢

转载自www.cnblogs.com/l75790/p/9181137.html