Ubuntu系統重啟後DNS配置丟失
方案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
方案二通過resolvconf實現配置
esolvconfig應用可以實現DNS資訊管理,可以通過下面的應用來安裝此元件:
sudo apt-get install resolvconf
建立/etc/default/resolvconf預設配置檔案,新增相關環境變數
[email protected]:/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配置項。
nameserver 10.220.0.11
nameserver 10.220.0.12
search infinera.com
使用下列配置命令使配置生效
sudo resolvconf -u
原文:https://blog.csdn.net/jinguangliu/article/details/70355813