Ubuntu每次重启后,/etc/resolv.conf里面设置的nameserver就会被清空,仔细看发现人家有提示:
# 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
原来Ubuntu的resolvconf 服务重启的时候/etc/resolv.conf 的内容会被修改成默认的样子,可以使用下面命令看一下:
# sudo service resolvconf restart
# sudo vim /etc/resolv.conf
而默认的内容则来自于/etc/resolvconf/resolv.conf.d/base,将要添加的内容配置在这个文件即可在每次重启服务的时候重置nameserver,如:
nameserver 192.168.1.2
当然,还有另外一种办法,那就是直接修改网卡配置文件/etc/network/interfaces:
iface eth0 inet static
address 192.168.3.3
netmask 255.255.255.0
gateway 192.168.3.1
dns-nameservers 192.168.3.45 192.168.8.10
最后一行就是DNS的地址,用空格隔开。