今天发现服务器ping不了域名,却能ping 通 ip
# ping www.baidu.com
ping: unknown host www.baidu.com
# ping 163.177.151.110
PING 163.177.151.110 (163.177.151.110) 56(84) bytes of data.
64 bytes from 163.177.151.110: icmp_seq=1 ttl=48 time=273 ms
查看 /etc/resolv.conf 显示 No nameservers found
# cat /etc/resolv.conf
# Generated by NetworkManager
search guest
# No nameservers found; try putting DNS servers into your
# ifcfg files in /etc/sysconfig/network-scripts like so:
#
# DNS1=xxx.xxx.xxx.xxx
# DNS2=xxx.xxx.xxx.xxx
# DOMAIN=lab.foo.com bar.foo.com
于是在配置文件下添加DNS
# vi /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
再尝试一下,ping正常
# ping www.google.com
PING www.google.com (172.217.1.100) 56(84) bytes of data.
64 bytes from mia09s17-in-f4.1e100.net (172.217.1.100): icmp_seq=1 ttl=57 time=0.813 ms
64 bytes from mia09s17-in-f4.1e100.net (172.217.1.100): icmp_seq=2 ttl=57 time=0.849 ms
如果问题没解决尝试以下修改
# vi /etc/nsswitch.conf
hosts: files dns
改成:
hosts: files dns wins
实际上重启后又不行了,需要在上面的基础上关闭 networkmanager 服务
临时关闭:
service networkmanager stop
永久关闭:
chkconfig NetworkManager off
重启一下~
# reboot
# ping www.google.com
PING www.google.com (216.58.219.164) 56(84) bytes of data.
64 bytes from mia07s27-in-f164.1e100.net (216.58.219.164): icmp_seq=1 ttl=57 time=0.547 ms
一切安静了