Linux 服务器ping不通域名 ping: unknown host www.baidu.com

2014-09-06

当 Linux 服务器 ping 不通域名, 出现如下提示:
[root@localhost ~]# ping www.baidu.com
ping: unknown host www.baidu.com

1.检测网络
首先确定已经连接上路由器,并且路由器能够访问外网,可以通过访问网关进行确定
[root@localhost ~]# ping 192.168.2.251
PING 192.168.2.251 (192.168.2.251) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=2.96 ms


如果确定网络没问题的情况下, 可以通过如下步骤寻找解决办法:


1) 确定设置了域名服务器, 没有的话, 建议设置 Google 的公共 DNS 服务, 它应该不会出问题的
[root@localhost ~]# vi /etc/resolv.conf
nameserver  192.168.2.251

2) 确保网关已设置
# grep GATEWAY /etc/sysconfig/network-scripts/ifcfg*
/etc/sysconfig/network-scripts/ifcfg-eth0:GATEWAY=192.168.2.251

如果未设置, 则通过如下方式增加网关:
# route add default gw 192.168.2.251
或者手工编写/etc/sysconfig/network-scripts/ifcfg*文件后, 重启 network 服务:
# service network restart


3) 确保可用 dns 解析
# grep hosts /etc/nsswitch.conf
hosts: files dns

成功结果:
如果以上哪个有问题, 修正后, 再测试, 应该就没问题了:
#ping  www.baidu.com
PING www.a.shifen.com (220.181.6.175) 56(84) bytes of data.
64 bytes from 220.181.6.175: icmp_seq=0 ttl=50 time=9.51 ms


posted @ 2014-09-06 17:15  淡蓝色的天空很美  阅读(528)  评论(0编辑  收藏  举报