今天将ubuntu进行了换源,换成了国内的阿里源,结果出现了ping百度出现不能ping通的问题,后来网上查找资料发现在/etc/resolv.conf中添加上固定ip时写的nameserver即可,结果却没发现resolv.conf文件中有一句话没仔细看,导致每次关机重启后,这个文件的修改内容被抹掉了,后来找到了一个解决办法,在固定ip时写上dns-nameservers 1.2.4.8 8.8.8.8 8.8.4.4等即可:我的/etc/network/interfaces下的原样文件如下:
1 # This file describes the network interfaces available on your system
2 # and how to activate them. For more information, see interfaces(5).
3
4 source /etc/network/interfaces.d/*
5
6 # The loopback network interface
7 auto lo
8 iface lo inet loopback
9
10 # The primary network interface
11 auto ens32
12 iface ens32 inet static
13 address 1.1.1.6
14 netmask 255.255.255.0
15 gateway 1.1.1.2
16 dns-nameservers 1.2.4.8 8.8.8.8 8.8.4.4
配置好了之后执行两个重启服务即可:
sudo /etc/init.d/resolvconf restart
sudo /etc/init.d/networking restart
再次关机后重启也不会出现以前的问题了,并且nameserver也配置到了resolv.conf文件中去了。