系统有访问微信接口,突然报错:couldn't resolve host api.weixin.qq.com。

发现ping可以访问百度ip

ping 39.156.66.14

from 39.156.66.14: icmp_seq=1 ttl=45 time=58.2 ms 64 bytes

from 39.156.66.14: icmp_seq=2 ttl=45 time=60.1 ms 64 bytes

from 39.156.66.14: icmp_seq=3 ttl=45 time=57.0 ms

但不能访问百度域名

[root@localhost ~]# ping www.baidu.com

ping: unknown host www.baidu.com

 

所以猜测是DNS问题

1. sudo vim /etc/network/interfaces

将dns修改为114.114.114.114

# interfaces(5) file used by ifup(8) and ifdown(8)

auto lo iface lo inet loopback auto eth0 iface eth0 inet static        

address 172.24.2.12        

netmask 255.255.255.0        

gateway 172.24.2.1        

dns-nameservers 114.114.114.114

 

2. sudo vim /etc/resolv.conf

同样修改dns为114.114.114.114

# 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 114.114.114.114

 

3. 重启网络

sudo service networking restart 

最后就可以访问了