CentOS ping: unknown host 解决方法
转自:http://blog.sina.com.cn/s/blog_8cf0057a0101a1ed.html
如果某台Linux(CentOS)服务器ping域名, 如下提示:
# ping www.sina.com
ping: unknown host www.sina.com
确认网络没问题的情况下, 可以通过如下步骤寻找解决办法:
1) 确认设置了域名服务器
# cat /etc/resolv.conf
nameserver 8.8.8.8 #(Google的公共DNS服务)
nameserver 8.8.4.4 #(Google的公共DNS服务)
2) 确认网关已设置/确认路由表正常
# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 10.10.10.1 0.0.0.0 UG 0 0 0 eth0
如果未设置, 则通过如下方式增加网关:
# route add default gw 10.245.75.1
# grep GATEWAY /etc/sysconfig/network-scripts/ifcfg*
/etc/sysconfig/network-scripts/ifcfg-eth0:GATEWAY=10.245.75.1
3) 确认可用dns解析
# grep hosts /etc/nsswitch.conf
hosts: files dns
以上的1) 2) 3) 点只是确认问题,个人喜欢手工编写配置文件,一次解决问题。
配置/etc/sysconfig/network-scripts/ifcfg-eth0文件后,重启network服务:
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
NM_CONTROLLED="yes"
ONBOOT=yes
TYPE=Ethernet
BOOTPROTO=static
IPADDR=10.245.75.240
#PREFIX=24
GATEWAY=10.245.75.1
DNS1=8.8.8.8
DNS2=8.8.4.4
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=yes
NAME="System eth0"
UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx # uuid
HWADDR=xx:xx:xx:xx:xx:xx # hwaddr
NETWORKING=yes
# service network restart