Skip to content

Commit c7ecd92

Browse files
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.
1 parent cabaebb commit c7ecd92

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

build_debian.sh

+7-2
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,8 @@ sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y in
397397
gpg \
398398
jq \
399399
auditd \
400-
linux-perf
400+
linux-perf \
401+
resolvconf
401402

402403
# default rsyslog version is 8.2110.0 which has a bug on log rate limit,
403404
# use backport version
@@ -687,7 +688,11 @@ sudo rm -f $ONIE_INSTALLER_PAYLOAD $FILESYSTEM_SQUASHFS
687688
## Note: -x to skip directories on different file systems, such as /proc
688689
sudo du -hsx $FILESYSTEM_ROOT
689690
sudo mkdir -p $FILESYSTEM_ROOT/var/lib/docker
690-
sudo cp files/image_config/resolv-config/resolv.conf $FILESYSTEM_ROOT/etc/resolv.conf
691+
692+
## Clear DNS configuration inherited from the build server
693+
sudo rm -f $FILESYSTEM_ROOT/etc/resolvconf/resolv.conf.d/original
694+
sudo cp files/image_config/resolv-config/resolv.conf.head $FILESYSTEM_ROOT/etc/resolvconf/resolv.conf.d/head
695+
691696
sudo mksquashfs $FILESYSTEM_ROOT $FILESYSTEM_SQUASHFS -comp zstd -b 1M -e boot -e var/lib/docker -e $PLATFORM_DIR
692697

693698
# Ensure admin gid is 1000

files/image_config/interfaces/interfaces-config.sh

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ for intf_pid in $(ls -1 /var/run/dhclient*.Ethernet*.pid 2> /dev/null); do
6060
[[ -f ${intf_pid} ]] && kill `cat ${intf_pid}` && rm -f ${intf_pid}
6161
done
6262

63+
[[ -f /var/run/resolvconf/interface/eth0.dhclient ]] && rm -f /var/run/resolvconf/interface/eth0.dhclient
64+
[[ -f /var/run/resolvconf/interface/eth0.ip6.dhclient ]] && rm -f /var/run/resolvconf/interface/eth0.ip6.dhclient
65+
6366
# Read sysctl conf files again
6467
sysctl -p /etc/sysctl.d/90-dhcp6-systcl.conf
6568

files/image_config/resolv-config/resolv.conf

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Dynamic resolv.conf(5) file generated by resolvconf(8)
2+
# The content of this file may be overwritten during a config reload.

0 commit comments

Comments
 (0)