linux:Temporary failure in name resolution&Couldn’t resolve host

所有域名无法正常解析。

  • ping www.baidu.com 等域名提示 Temporary failure in name resolution错误。
root@localhost:~# ping www.baidu.com
ping: www.baidu.com: Temporary failure in name resolution
root@localhost:~# 

一、ubuntu/debian(emporary failure in name resolution)

1、修改/etc/resolv.conf配置文件

sudo vim /etc/resolv.conf 

添加如下内容:nameserver 8.8.8.8
linux:Temporary failure in name resolution&Couldn’t resolve host_第1张图片

然后重新试下,访问正常

root@localhost:~# ping www.baidu.com
PING www.a.shifen.com (39.156.66.18) 56(84) bytes of data.
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=1 ttl=52 time=21.9 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=2 ttl=52 time=21.8 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=3 ttl=52 time=37.3 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=4 ttl=52 time=23.0 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=5 ttl=52 time=32.4 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=6 ttl=52 time=42.5 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=7 ttl=52 time=22.0 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=8 ttl=52 time=25.9 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=9 ttl=52 time=22.1 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=10 ttl=52 time=42.2 ms
^C
--- www.a.shifen.com ping statistics ---
10 packets transmitted, 10 received, 0% packet loss, time 28ms
rtt min/avg/max/mdev = 21.801/29.118/42.487/8.263 ms
root@localhost:~# 

二、 CentOS(Couldn’t resolve host)

CentOS 下面直接修改 /etc/resolv.conf 不行,因为该文件调用了 /etc/sysconfig/network-scripts/ifcfg-eth0 的配置预设,既然知道了这两个文件的工作原理,那么我们必须要在 /etc/sysconfig/ network-scripts/ifcfg-eth0 里面最后加上 dns 地址让 resolv.conf 来调用。否则重启后,因为 eth0 中没有预设 dns 的相关信息,就会使 /etc/resolv.conf 恢复到原来的状态,解析还是不成功。

修改 /etc/sysconfig/network-scripts/ifcfg-eth0 文件

最后加上两行

DNS1=8.8.8.8
DNS2=8.8.4.4

改完后重启网卡

service network restart

重启后再查看 /etc/resolv.conf 文件是这样的:

# Generated by NetworkManager
search webhostbox.net
nameserver 8.8.8.8

你可能感兴趣的:(经验记录,linux,运维,服务器)