Skip to content

Commit 119cd10

Browse files
Clear DNS configuration received from DHCP during networking reconfiguration in Linux. (sonic-net#13516)
- Why I did it fixes sonic-net#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 4355911 commit 119cd10

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
@@ -385,7 +385,8 @@ sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y in
385385
gpg \
386386
jq \
387387
auditd \
388-
linux-perf
388+
linux-perf \
389+
resolvconf
389390

390391
# Have systemd create the auditd log directory
391392
sudo mkdir -p ${FILESYSTEM_ROOT}/etc/systemd/system/auditd.service.d
@@ -661,7 +662,11 @@ sudo rm -f $ONIE_INSTALLER_PAYLOAD $FILESYSTEM_SQUASHFS
661662
## Note: -x to skip directories on different file systems, such as /proc
662663
sudo du -hsx $FILESYSTEM_ROOT
663664
sudo mkdir -p $FILESYSTEM_ROOT/var/lib/docker
664-
sudo cp files/image_config/resolv-config/resolv.conf $FILESYSTEM_ROOT/etc/resolv.conf
665+
666+
## Clear DNS configuration inherited from the build server
667+
sudo rm -f $FILESYSTEM_ROOT/etc/resolvconf/resolv.conf.d/original
668+
sudo cp files/image_config/resolv-config/resolv.conf.head $FILESYSTEM_ROOT/etc/resolvconf/resolv.conf.d/head
669+
665670
sudo mksquashfs $FILESYSTEM_ROOT $FILESYSTEM_SQUASHFS -e boot -e var/lib/docker -e $PLATFORM_DIR
666671

667672
# 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)