如果某台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
如果确定網絡沒問題的情況下, 可以通過如下步驟尋找解決辦法:
1) 确定設定了域名伺服器, 沒有的話, 建議設定Google的公共DNS服務, 它應該不會出問題的
[root@localhost ~]# cat /etc/resolv.conf
search localdomain
因為我的DNS沒有設定是以導緻了ping外網ping不通。将dns添加到該檔案中
[root@localhost ~]# 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
如果以上哪個有問題, 修正後, 再測試, 應該就沒問題了:
#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
原文位址:https://blog.csdn.net/qq_35370485/article/details/77844860