From 28886b56cf9112f401453c223be522db8ebbbfa5 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Mon, 26 Aug 2024 21:19:36 -0700 Subject: [PATCH] names, network: Re-feed DNS known to network-manager to resolved - This avoids using fallback DNS servers in systemd-resolved soon after systemd-resolved takes over /etc/resolv.conf and if network-manager knows some DNS servers from the connections it has established. - Version for the names app has already been incremented in this patch series. Signed-off-by: Sunil Mohan Adapa Reviewed-by: Veiko Aasa --- plinth/modules/names/__init__.py | 11 ++++++++++- plinth/network.py | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/plinth/modules/names/__init__.py b/plinth/modules/names/__init__.py index 30c5fc110..f34137de2 100644 --- a/plinth/modules/names/__init__.py +++ b/plinth/modules/names/__init__.py @@ -8,7 +8,7 @@ import logging from django.utils.translation import gettext_lazy as _ from plinth import app as app_module -from plinth import cfg, menu +from plinth import cfg, menu, network from plinth.daemon import Daemon from plinth.modules.backups.components import BackupRestore from plinth.package import Packages @@ -82,6 +82,15 @@ class NamesApp(app_module.App): # FreedomBox. service_privileged.restart('systemd-resolved') + # After systemd-resolved is freshly installed, /etc/resolve.conf + # becomes a symlink to configuration pointing to systemd-resovled stub + # resolver. However, the old contents are not fed from network-manager + # (if it was present earlier and wrote to /etc/resolve.conf). Ask + # network-manager to feed the DNS servers from the connections it has + # established to systemd-resolved so that using fallback DNS servers is + # not necessary. + network.refeed_dns() + self.enable() diff --git a/plinth/network.py b/plinth/network.py index d545449af..6e6fb105a 100644 --- a/plinth/network.py +++ b/plinth/network.py @@ -622,3 +622,8 @@ def wifi_scan(): }) return access_points + + +def refeed_dns(): + """Re-feed DNS servers to systemd-resolved.""" + get_nm_client().reload(nm.ManagerReloadFlags.DNS_RC)