From 262a631375a294e92329dac8c370ebfb00b7833d Mon Sep 17 00:00:00 2001 From: Mat Kowalski Date: Sat, 24 Jul 2021 13:48:44 +0200 Subject: [PATCH] Do not remove upstream DNS configuraton in cleanup This PR changes the logic of host cleanup so that the upstream DNS configuration is not removed. This comes from the fact that by default dev-scripts configure NetworkManager to use dnsmasq with DHCP-provided DNS servers and removes the existing /etc/resolv.conf configuration. This causes problems in environments configured without DHCP with DNS servers configured manually without use of the NetworkManager. With this PR user can use `ADDN_DNS` variable to provide their own DNS servers that will be passed to the dnsmasq. At the same time when removing dev-scripts from the system, the backup of the original /etc/resolv.conf will be restored so that the initial system configuration is reverted. --- host_cleanup.sh | 1 + utils.sh | 3 +++ 2 files changed, 4 insertions(+) diff --git a/host_cleanup.sh b/host_cleanup.sh index f508f7280..53f20dc70 100755 --- a/host_cleanup.sh +++ b/host_cleanup.sh @@ -39,6 +39,7 @@ if systemctl is-active --quiet NetworkManager; then else sudo systemctl restart NetworkManager fi +mv /etc/resolv.conf.dev-scripts.backup /etc/resolv.conf # There was a bug in this file, it may need to be recreated. # delete the interface as it can cause issues when not rebooting diff --git a/utils.sh b/utils.sh index 99b2876c9..6104512c8 100755 --- a/utils.sh +++ b/utils.sh @@ -536,6 +536,9 @@ function write_pull_secret() { } function switch_to_internal_dns() { + # Create backup of the current resolv.conf in case user is using a manual configuration. This + # file will be used in host_cleanup to revert the initial DNS configuration of the host. + cp /etc/resolv.conf /etc/resolv.conf.dev-scripts.backup sudo mkdir -p /etc/NetworkManager/conf.d/ ansible localhost -b -m ini_file -a "path=/etc/NetworkManager/conf.d/dnsmasq.conf section=main option=dns value=dnsmasq" if [ "$ADDN_DNS" ] ; then