centso可以访问外网,但是ping www.baidu.com ping: unknown host www.badidu.com
解决办法:
首先要想到是否设置了域名服务器
nameserver dnsip地址
确保路由表正常
Destination Gateway Genmask Flags
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 UG
0 0 0 eth0
确保可用dns解析
# grep hosts /etc/nsswitch.conf
hosts: files dns
上面的配置解释说明:
hosts: files dns 表示将使用/etc/hosts文件解析主机,如果无法解析主机名将使用DNS解析。 hosts: dns files 表示只在DNS失效时候才使用/etc/hosts文件 hosts: dns 表示只用DNS解析主机 host: files 表示只用/etc/hosts文件解析主机