如果某台 Linux http://lib.csdn.net/base/linux 服务器 ping 不通域名, 如下提示:
- [root@localhost http://my.oschina.net/u/570656 ~]# ping www.baidu.com
- ping: unknown host www.baidu.com
首先确定已经连接上路由器, 并且路由器能够访问外网, 可以通过访问网关进行确定
- [root@localhost http://my.oschina.net/u/570656 ~]# ping 8.8.8.8
- 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
- 64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=1.75 ms
如果确定网络没问题的情况下, 可以通过如下步骤寻找解决办法:
1) 确定设置了域名服务器, 没有的话, 建议设置 Google 的公共 DNS 服务, 它应该不会出问题的
- [root@localhost http://my.oschina.net/u/570656 ~]# cat /etc/resolv.conf
- search localdomain
因为我的 DNS 没有设置所以导致了 ping 外网 ping 不通. 将 dns 添加到该文件中
- [root@localhost http://my.oschina.net/u/570656 ~]# vi /etc/resolv.conf
- nameserver 202.98.96.68
- nameserver 61.139.2.69
- ~
或者加入 192.168.1.1 (默认网关)
2) 确保网关已设置
- # grep GATEWAY /etc/sysconfig/network-scripts/ifcfg*
- -----------------------
- /etc/sysconfig/network-scripts/ifcfg-eth0:GATEWAY=192.168.40.1
- -----------------------
如果未设置, 则通过如下方式增加网关:
# route add default gw 192.168.40.1
或者手工编写 / etc/sysconfig/network-scripts/ifcfg * 文件后, 重启 network 服务:
# service network restart
3) 确保可用 dns 解析
- # grep hosts /etc/nsswitch.conf
- -----------------------
- hosts: files dns
- -----------------------
如果以上哪个有问题, 修正后, 再测试 http://lib.csdn.net/base/softwaretest , 应该就没问题了:
- #ping -c 3 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
- 64 bytes from 220.181.6.175: icmp_seq=1 ttl=50 time=8.45 ms
- 64 bytes from 220.181.6.175: icmp_seq=2 ttl=50 time=8.97 ms
- - www.a.shifen.com ping statistics -
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 8.450/8.977/9.511/0.446 ms, pipe 2
来源: http://www.bubuko.com/infodetail-3080939.html