From 5ef488f808f0b92ff5aadf4f7c106e06163e276c Mon Sep 17 00:00:00 2001 From: Oleksandr Ivantsiv Date: Mon, 30 Jan 2023 21:13:10 +0100 Subject: [PATCH] Clear DNS configuration received from DHCP during networking reconfiguration in Linux. (#13516) - Why I did it fixes #12907 When the management interface IP address configuration changes from dynamic to static the DNS configuration (retrieved from the DHCP server) in /etc/resolv.conf remains uncleared. This leads to a DNS configuration pointing to the wrong nameserver. To make the behavior clear DNS configuration received from DHCP should be cleared. - How I did it Use resolvconf package for managing DNS configuration. It is capable of tracking the source of DNS configuration and puts the configuration retrieved from the DHCP servers into a separate file. This allows the implementation of DNS configuration cleanup retrieved from DHCP during networking reconfiguration. - How to verify it Ensure that the management interface has no static configuration. Check that /etc/resolv.conf has DNS configuration. Configure a static IP address on the management interface. Verify that /etc/resolv.conf has no DNS configuration. Remove the static IP address from the management interface. Verify that /etc/resolv.conf has DNS configuration retrieved form DHCP server. --- build_debian.sh | 9 +++++++-- files/image_config/interfaces/interfaces-config.sh | 3 +++ files/image_config/resolv-config/resolv.conf | 0 files/image_config/resolv-config/resolv.conf.head | 2 ++ 4 files changed, 12 insertions(+), 2 deletions(-) delete mode 100644 files/image_config/resolv-config/resolv.conf create mode 100644 files/image_config/resolv-config/resolv.conf.head diff --git a/build_debian.sh b/build_debian.sh index 1461b176c7..180a427cac 100755 --- a/build_debian.sh +++ b/build_debian.sh @@ -386,7 +386,8 @@ sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y in gpg \ jq \ auditd \ - linux-perf + linux-perf \ + resolvconf # default rsyslog version is 8.2110.0 which has a bug on log rate limit, # use backport version @@ -674,7 +675,11 @@ sudo rm -f $ONIE_INSTALLER_PAYLOAD $FILESYSTEM_SQUASHFS ## Note: -x to skip directories on different file systems, such as /proc sudo du -hsx $FILESYSTEM_ROOT sudo mkdir -p $FILESYSTEM_ROOT/var/lib/docker -sudo cp files/image_config/resolv-config/resolv.conf $FILESYSTEM_ROOT/etc/resolv.conf + +## Clear DNS configuration inherited from the build server +sudo rm -f $FILESYSTEM_ROOT/etc/resolvconf/resolv.conf.d/original +sudo cp files/image_config/resolv-config/resolv.conf.head $FILESYSTEM_ROOT/etc/resolvconf/resolv.conf.d/head + sudo mksquashfs $FILESYSTEM_ROOT $FILESYSTEM_SQUASHFS -comp zstd -b 1M -e boot -e var/lib/docker -e $PLATFORM_DIR # Ensure admin gid is 1000 diff --git a/files/image_config/interfaces/interfaces-config.sh b/files/image_config/interfaces/interfaces-config.sh index f6aa4147a4..9613493846 100755 --- a/files/image_config/interfaces/interfaces-config.sh +++ b/files/image_config/interfaces/interfaces-config.sh @@ -60,6 +60,9 @@ for intf_pid in $(ls -1 /var/run/dhclient*.Ethernet*.pid 2> /dev/null); do [[ -f ${intf_pid} ]] && kill `cat ${intf_pid}` && rm -f ${intf_pid} done +[[ -f /var/run/resolvconf/interface/eth0.dhclient ]] && rm -f /var/run/resolvconf/interface/eth0.dhclient +[[ -f /var/run/resolvconf/interface/eth0.ip6.dhclient ]] && rm -f /var/run/resolvconf/interface/eth0.ip6.dhclient + # Read sysctl conf files again sysctl -p /etc/sysctl.d/90-dhcp6-systcl.conf diff --git a/files/image_config/resolv-config/resolv.conf b/files/image_config/resolv-config/resolv.conf deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/files/image_config/resolv-config/resolv.conf.head b/files/image_config/resolv-config/resolv.conf.head new file mode 100644 index 0000000000..db81bded75 --- /dev/null +++ b/files/image_config/resolv-config/resolv.conf.head @@ -0,0 +1,2 @@ +# Dynamic resolv.conf(5) file generated by resolvconf(8) +# The content of this file may be overwritten during a config reload.