码迷,mamicode.com
首页 > 系统相关 > 详细

LINUX 解决linux ping: unknown host www.baidu.com

时间:2018-09-07 11:55:01      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:sea   1.9   localhost   5.4   增加   域名   cal   ttl   www.   

当系统提示:

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

时,首先看看能否ping通路由器,并且路由器能够连接上外网

[root@localhost ~]# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=128 time=123 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=128 time=175 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=128 time=196 ms
^C
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 123.681/165.315/196.354/30.601 ms

如果网络安全没有问题且可以ping通

确定已经设置了域名服务器, 如果没有, 推荐设置DNS服务,

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

因为我的DNS没有设置所以导致了ping外网ping不通。

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

nameserver (自己的IP)

或者加入(网关)

确保网关已设置 :

[root@localhost ~]# grep GATEWAY /etc/sysconfig/network-scripts/ifcfg*
/etc/sysconfig/network-scripts/ifcfg-eno16777736:GATEWAY=192.168.100.2

如果未设置, 可以用以下方式增加网关: 

# route add default gw 192.168.100.2

确定可用dns解析 

# grep hosts /etc/nsswitch.conf

[root@localhost ~]# grep hosts /etc/nsswitch.conf
#hosts: db files nisplus nis dns
hosts: files dns

修复了以上问题,在尝试用ping一下www.baidu.com

[root@localhost ~]# ping www.baidu.com
PING www.a.shifen.com (183.232.231.173) 56(84) bytes of data.
64 bytes from 183.232.231.173: icmp_seq=1 ttl=128 time=31.9 ms
64 bytes from 183.232.231.173: icmp_seq=2 ttl=128 time=26.0 ms
64 bytes from 183.232.231.173: icmp_seq=3 ttl=128 time=26.0 ms
64 bytes from 183.232.231.173: icmp_seq=4 ttl=128 time=25.4 ms
64 bytes from 183.232.231.173: icmp_seq=5 ttl=128 time=25.6 ms
64 bytes from 183.232.231.173: icmp_seq=6 ttl=128 time=37.5 ms
64 bytes from 183.232.231.173: icmp_seq=7 ttl=128 time=27.3 ms

LINUX 解决linux ping: unknown host www.baidu.com

标签:sea   1.9   localhost   5.4   增加   域名   cal   ttl   www.   

原文地址:https://www.cnblogs.com/Zxiaotian/p/9603505.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!