红联Linux门户
Linux帮助

Ubuntu系统重启后/etc/resolv.conf内容丢失

发布时间:2017-05-30 09:41:55来源:linux网站作者:Think-througher
简介
简要介绍如何解决Ubuntu系统重启后/etc/resolv.conf内容丢失问题,或者说解决永久保存/etc/resolv.conf配置问题。
 
方案1、通过/etc/network/interfaces配置
通过向/etc/network/interfaces接口配置文件追加dns-nameserver和dns-search项来永久保存配置,保存完成后执行"sudo service networing restart"重启网络来触发更新/etc/resolv.conf文件。
The ifup program can be used to configure network interfaces according to settings in /etc/network/interfaces. To  make ifup  push  nameserver  information  to resolvconf when it configures an interface the administrator must add dns- option lines to the relevant  iface  stanza  in  interfaces(5).   The  following  option  names  are  accepted:  dns-nameserver,dns-search, and dns-sortlist.
To  add  a nameserver IP address, add an option line consisting of dns-nameserver and the address.  To add multiple name server addresses, include multiple such dns-nameserver lines.
dns-nameserver 192.168.1.254
dns-nameserver 8.8.8.8
To add search domain names, add a line beginning with dns-search.
dns-search foo.org bar.com
The dns-nameservers option is also accepted and, unlike dns-nameserver, can be given  multiple  arguments,  separated  by spaces.
The dns-domain option is deprecated in favor of dns-search.
The resulting stanza might look like the following example.
iface eth0 inet static
address 192.168.1.3
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameserver 192.168.1.254
dns-nameserver 8.8.8.8
dns-search foo.org bar.com
 
方案2、通过resolvconf实现配置
resolvconfig应用可以实现DNS信息管理,可以通过下面的应用来安装此组件:
sudo apt-get install resolvconf
创建/etc/default/resolvconf缺省配置文件,添加相关环境变量
bob@ubuntu:/etc/resolvconf/resolv.conf.d$ cat /etc/default/resolvconf   
TRUNCATE_NAMESERVER_LIST_AFTER_127=no
该环境变量影响保存到/etc/resolv.conf的DNS配置条数。向/etc/resolvconf/resolv.conf/base配置文件中添加DNS配置项。
bob@ubuntu:/etc/resolvconf/resolv.conf.d$ cat base  
nameserver 10.220.0.11  
nameserver 10.220.0.12  
search infinera.com
使用下列配置命令使配置生效
sudo resolvconf -u
 
总结
以上两种配置方式均可实现/etc/resolv.conf配置永久保存功能,更具体的信息可以查看"man resolvconf"手册。
 
本文永久更新地址:http://www.linuxdiyf.com/linux/31154.html