From 5d6156454bf8f6dab4a5fdd7e1bf6cdc72c09456 Mon Sep 17 00:00:00 2001 From: "David Kaspar [Dee'Kej]" Date: Mon, 30 Oct 2017 17:08:42 +0100 Subject: ifup-post: always update nameserver & search entries in /etc/resolv.conf This is complete rework of how we generate the /etc/resolv.conf. Fixes: * always update 'nameserver' & 'search' entries when DNS* & DOMAIN options (respectively) were updated in ifcfg-* files * always update the order of 'nameserver' entries when the order of DNS* options was updated * always keep /etc/resolv.conf.save as a proper backup - do not overwrite it everytime when updating 'nameserver' or 'search' Enhancements: * added support for DNS3 option (equals to MAXNS value in GLIBC) * added logic to process duplicate DNS* options * added logic to process randomly omitted DNS* options (e.g. omitting DNS1 while specifying DNS2 and/or DNS3 will still work now) This work was based on these two RHEL-7.5 BZs: https://bugzilla.redhat.com/show_bug.cgi?id=1364895 https://bugzilla.redhat.com/show_bug.cgi?id=1357658 --- sysconfig/network-scripts/network-functions | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'sysconfig/network-scripts/network-functions') diff --git a/sysconfig/network-scripts/network-functions b/sysconfig/network-scripts/network-functions index d7915e31..9d6f9366 100644 --- a/sysconfig/network-scripts/network-functions +++ b/sysconfig/network-scripts/network-functions @@ -448,6 +448,10 @@ set_hostname () rsctmp=$(mktemp /tmp/XXXXXX); cat /etc/resolv.conf > $rsctmp echo "search $domain" >> $rsctmp + + # Backup resolv.conf only if it doesn't exist already: + ! [ -f /etc/resolv.conf.save ] && cp -af /etc/resolv.conf /etc/resolv.conf.save + change_resolv_conf $rsctmp /bin/rm -f $rsctmp fi @@ -697,3 +701,32 @@ net_log() fi return 0 } + +update_DNS_entries() +{ + # Remove duplicate values from DNS options if any: + if [ -n "${DNS3}" ] && [[ "${DNS3}" == "${DNS2}" || "${DNS3}" == "${DNS1}" ]]; then + unset DNS3 + fi + + if [ -n "${DNS2}" ] && [[ "${DNS2}" == "${DNS1}" ]]; then + unset DNS2 + fi + + # Shift the DNS options if necessary: + if [ -z "${DNS1}" ] && [ -n "${DNS2}" ]; then + DNS1="${DNS2}" + unset DNS2 + fi + + if [ -z "${DNS2}" ] && [ -n "${DNS3}" ]; then + DNS2="${DNS3}" + unset DNS3 + fi + + # We need to check DNS1 again in case only DNS3 was set at all: + if [ -z "${DNS1}" ] && [ -n "${DNS2}" ]; then + DNS1="${DNS2}" + unset DNS2 + fi +} -- cgit v1.2.1