nameservers erased after systemctl restart network.service
You're probably mixing the classic /etc/init.d/network
(which gets translated to network.service
) with NetworkManager.service
. While those are expected to partially coexist, it's much better to choose just one of them and stop and disable the other.
Either way, it's better not to write /etc/resolv.conf
directly but instead properly configure /etc/sysconfig/network
and/or /etc/sysconfig/network-scripts/ifup-*
files.
You should either enable dhcp or set the name servers manually in /etc/sysconfig
.
Example (DHCP):
BOOTPROTO=dhcp
Example (static):
BOOTPROTO=none
DNS1=192.168.1.1
If you really want to set /etc/resolv.conf
directly and you want to make sure NetworkManager won't overwrite it, you can set it up in /etc/NetworkManager/NetworkManager.conf
.
[main]
dns=none
Regarding your additional question on the number of name servers, you should never need more than one or two name servers in /etc/resolv.conf
. You shouldn't expect much from the libc resolver behavior, it just attempts the name servers in order and you'll experience long delays if you have defunct name servers in the list.
I don't know your reasons to use more than three name servers. But if there is one, you definitely need to configure a local forwarding DNS server like unbound or dnsmasq and point /etc/resolv.conf
to 127.0.0.1
. For the best experience with dynamic configuration you should use NetworkManager in this case.
NetworkManager with dnsmasq has been long supported and is the default on Ubuntu and possibly other distributions.
[main]
dns=dnsmasq
NetworkManager with unbound is in alpha quality in the lastest NetworkManager versions and currently also needs dnssec-trigger as the main use case is to provide DNSSEC validation on the local host.
[main]
dns=unbound
Both dnsmasq and unbound plugins configure /etc/resolv.conf
to nameserver 127.0.0.1
for you and each of them configures the respective local DNS server.