linux:ping不通www.baidu.com

如果某台Linux服务器ping不通域名, 如下提示:

[root@localhost ~]# ping www.baidu.com

ping: unknown host www.baidu.com

首先确定已经连接上路由器,并且路由器能够访问外网,可以通过访问网关进行确定

[root@localhost ~]# ping 192.168.1.1

PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.

64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=2.96 ms

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

1) 确定设置了域名服务器

[root@localhost ~]# cat /etc/resolv.conf

因为我的DNS没有设置所以导致了ping外网ping不通。将dns添加到该文件中

[root@localhost ~]# vi /etc/resolv.conf

nameserver 192.168.1.1    (默认网关)

2) 确保网关已设置

# grep GATEWAY /etc/sysconfig/network-scripts/ifcfg*

/etc/sysconfig/network-scripts/ifcfg-eth0:GATEWAY=192.168.1.1

如果未设置, 则通过如下方式增加网关:

# route add default gw 192.168.1.1

# service network restart         (重启网关设置)

3) 确保可用dns解析

# grep hosts /etc/nsswitch.conf

hosts:      files dns

接下来就可以ping通百度了

#ping -c 3 www.baidu.com

ING 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 @ 2017-11-27 11:32  爱吃橙子  阅读(28314)  评论(0编辑  收藏  举报