问题原文
原帖链接 · Adam C · CC BY-SA 3.0
CentOS will wipe out any manual changes made to /etc/resolv.conf periodically. The defaults in Linux are poor in terms of failing over in a reasonable time (query name servers in same order every time, 5 second timeout, 2 retries).
Hence, the first DNS in your resolv.conf is essentially critical path. If it fails you can be looking at 10 seconds before you fail over.
These defaults are tweakable (see resolv.conf man page), but how can any changes be made permanent in CentOS and persist through reboots etc.?
社区高分解答
原帖链接 · Thomas Guyot-Sionnest · CC BY-SA 4.0
The accepted answer is when using legacy networking scripts. If you use NetworkManager you might not even have /etc/sysconfig/network, and if you do it will still not be used for connections managed by NetworkManager.
If you use NetworkManager:
To add options, ex adding rotate to bond0:
nmcli con mod bond0 +ipv4.dns-options rotate
To remove that option:
nmcli con mod bond0 -ipv4.dns-options rotate
The + is good to change options too; NetworkManager is smart enough to detect existing options and update them. For example, changing the timeout value:
root@debian:~# nmcli con show bond0 |grep ipv4.dns-options
ipv4.dns-options: "rotate,timeout:5"
root@debian:~# nmcli con mod bond0 +ipv4.dns-options timeout:3
root@debian:~# nmcli con show bond0 |grep ipv4.dns-options
ipv4.dns-options: "rotate,timeout:3"
This means the value is ignored for remove and not even needed. To remove timeout:
nmcli con mod bond0 -ipv4.dns-options timeout
It will work with a timeout value too but that value will be ignored, so removing timeout:5 will also remove any other timeout value.
NB: While looking into this I came across a related bug that was fixed in network-manager v1.14.6, v1.15.2-dev and v1.16. If you encounter any issue check your network-manager version first.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
