本文介绍了ping: unknown host问题的原因与解决方法,在linux系统下ping某网站域名时提示:ping: unknown host,分享下解决方法,在linux和solaris系统下验证有效。
ping: unknown host解决方法
在linux系统下,如果ping命令返回如下错误,可能是系统dns设置有误。
 
复制代码 代码示例:
[root@
centos5 ~]# ping www.sina.com.cn  
ping: unknown host www.sina.com.cn 
 解决方法如下(在linux和solaris系统下通过验证):
1) 确定设置了域名服务器
若无,则建议设置google的公共dns服务,当然了,阿里推出的公共dns(223.5.5.5、223.6.6.6)也是不错的。
 
# cat /etc/resolv.conf  
---------------------------- 
nameserver 8.8.8.8  
nameserver 8.8.4.4  
----------------------------
2) 确保路由表正常
 
[root@CentOS5 ~]# netstat -rn  
Kernel IP routing table  
Destination     Gateway Genmask Flags   MSS Window  irtt Iface  
192.168.128.0   0.0.0.0 255.255.255.0   U 0 0  0 
eth0  
169.254.0.0     0.0.0.0 255.255.0.0     U 0 0  0 eth0  
0.0.0.0 192.168.128.2   0.0.0.0 UG0 0  0 eth0 
如果未设置, 则通过如下方式增加网关:
 
# route add default gw 192.168.128.2 
3)、确保可用dns解析,不要忘记这一步哦。
 
# grep hosts /etc/nsswitch.conf  
------------------------------------  
hosts:      files dns  
------------------------------------
 
注意,以上配置要加上dns。
以下是dns的配置,备忘。
hosts: dns files
表示只在DNS失效时候才使用/etc/hosts文件
 
hosts: dns 
表示只用DNS解析主机
 
host: files 
表示只用/etc/hosts文件解析主机
 
hosts: files dns
将使用/etc/hosts文件解析主机,表示如果无法解析主机名将使用DNS。