服务器ping不通域名,却能ping通ip

今天发现服务器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

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 127.0.1.1

于是在配置文件下添加DNS

# sudo vim /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4

再尝试一下,ping正常

$ ping www.baidu.com
PING www.a.shifen.com (14.215.177.38) 56(84) bytes of data.
64 bytes from 14.215.177.38: icmp_seq=1 ttl=56 time=9.20 ms
64 bytes from 14.215.177.38: icmp_seq=2 ttl=56 time=9.24 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

一切都安静了。。。

参考:
https://blog.csdn.net/weixin_38196258/article/details/84287734

你可能感兴趣的:(ubuntu,ip,域名)