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

当系统提示:

[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

转载于:https://www.cnblogs.com/Zxiaotian/p/9603505.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值