本文主要是介绍Ubuntu系统重启后/etc/resolv.conf内容丢失,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
简介
简要介绍如何解决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 makeifup push nameserver information to resolvconf when it configures an interface the administrator must add dns- optionlines 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 nameserver addresses, include multiple such dns-nameserver lines.dns-nameserver 192.168.1.254dns-nameserver 8.8.8.8To add search domain names, add a line beginning with dns-search.dns-search foo.org bar.comThe dns-nameservers option is also accepted and, unlike dns-nameserver, can be given multiple arguments, separated byspaces.The dns-domain option is deprecated in favor of dns-search.The resulting stanza might look like the following example.iface eth0 inet staticaddress 192.168.1.3netmask 255.255.255.0gateway 192.168.1.1dns-nameserver 192.168.1.254dns-nameserver 8.8.8.8dns-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"手册。
这篇关于Ubuntu系统重启后/etc/resolv.conf内容丢失的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!