解決方案:
若是某臺Linux服務器ping不通域名, 以下提示:
[root@localhost ~]# ping www.baidu.com
ping: unknown host www.baidu.com 服務器
首先肯定已經鏈接上路由器,而且路由器可以訪問外網,能夠經過訪問網關進行肯定 網絡
[root@localhost ~]# 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 dom
若是肯定網絡沒問題的狀況下, 能夠經過以下步驟尋找解決辦法:
1) 肯定設置了域名服務器, 沒有的話, 建議設置Google的公共DNS服務, 它應該不會出問題的
[root@localhost ~]# cat /etc/resolv.conf 測試
search localdomain spa
由於個人DNS沒有設置因此致使了ping外網ping不通。將dns添加到該文件中 .net
[root@localhost ~]# vi /etc/resolv.conf rest
nameserver 202.98.96.68
nameserver 61.139.2.69
~ server
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
-------------------------------------------------------------------
若是以上哪一個有問題, 修正後, 再測試, 應該就沒問題了:
#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 dns