ubuntu20.04——能ping通ip却ping不通域名

问题:

# 百度IP可以ping通
(venv) root@p006:/etc# ping 220.181.38.150
PING 220.181.38.150 (220.181.38.150) 56(84) bytes of data.
64 bytes from 220.181.38.150: icmp_seq=1 ttl=47 time=15.5 ms
64 bytes from 220.181.38.150: icmp_seq=2 ttl=47 time=14.6 ms

# 域名却ping不通
(venv) root@p006:/etc# ping www.baidu.com
ping: www.baidu.com: Name or service not known

解决:

查看 /etc/resolv.conf 显示 No nameservers found,添加 DNS 地址,重启服务

(venv) root@p006:/etc# vim  /etc/resolv.conf
……
nameserver 114.114.114.114

(venv) root@p006:/etc# systemctl restart systemd-resolved

再尝试一下,ping正常 (其实我这里是不通的,只是这个问题常见,所以记录下)

那么域名还是 ping 不通,接着往下

(venv) root@p006:/etc# vi /etc/nsswitch.conf
hosts:          files					# 修改前
↓↓↓↓↓↓↓
hosts:          files dns wins			# 修改后(注意:wins	可不写)

这时就可以 ping 通域名了

(venv) root@p006:/etc# ping baidu.com
PING baidu.com (220.181.38.251) 56(84) bytes of data.
64 bytes from 220.181.38.251 (220.181.38.251): icmp_seq=1 ttl=47 time=15.0 ms

为防止重启失效,需要在此基础上关闭 networkmanager 服务

(venv) root@p006:/etc# service  networkmanager stop			# 临时关闭
(venv) root@p006:/etc# chkconfig NetworkManager off			# 永久关闭

重启 (此步骤可忽略)

(venv) root@p006:/etc# reboot
(venv) root@p006:/etc# ping baidu.com
PING baidu.com (220.181.38.251) 56(84) bytes of data.
64 bytes from 220.181.38.251 (220.181.38.251): icmp_seq=1 ttl=47 time=15.0 ms

个人记录

tail -2 /etc/systemd/resolved.conf



echo "DNS=114.114.114.114" >> /etc/systemd/resolved.conf
systemctl restart systemd-resolved
systemctl enable systemd-resolved
mv /etc/resolv.conf /etc/resolv.conf.bak
ln -s /run/systemd/resolve/resolv.conf /etc/
tail -2 /etc/resolv.conf
ping -c 2 baidu.com

  • 4
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值