How do I permanently configure the DNS resolution in Ubuntu for ALL programs/layers for specific interfaces
6
votes
1
answer
47302
views
Is there a way I can permanently set the DNS preference of my Ubuntu laptop for specific network interfaces?
I am relying on a wifi network that is not that predictable.
I don't have access to the edit-mode of the wifi router management console, and every now and then the wifi connection drops off and then comes back again.
This means I have to constantly invoke this command to "refresh" my DNS entries:
sudo resolvectl dns 3 1.1.1.1 8.8.8.8
.
The problem originally generated from web browser DNS_*
errors (many different e.g. DNS_PROBE_STARTED
, DNS_PROBE_FINISHED_NO_INTERNET
, DNS_PROBE_FINISHED_NXDOMAIN
, DNS_PROBE_FINISHED_BAD_CONFIG
, DNS_PROBE_FINISHED_NO_INTERNET
etc) I was seeing, so I figured out this wifi network (router)
is using dedicated DNS entries from the ISP (Internet Service Provider).
I can see these details (custom IP addresses) on the router config dashboard but I cannot change those settings.
Also: I can see that my Ubuntu DNS relies on the default gateway of the wifi network (the router).
I found this out with these commands where the IP addresses match:
# check my local Ubuntu DNS details for all interfaces
resolvectl dns
# find out the default gateway (it should be the router IP address)
ip route
I think this means that my laptop is dynamically relying on the gateway (router) for DNS resolution and that the router is configured to use some obscure IP addresses from the ISP (Internet Service Provider). Is this correct?
I changed the Global DNS by modifying this file /etc/systemd/resolved.conf
by appending this:
DNS=1.1.1.1 8.8.8.8
FallbackDNS=8.8.4.4
Then I did this:
# make sure to restart the DNS daemon
sudo systemctl restart systemd-resolved.service
# check what DNS is being used by each interface
resolvectl status
But of course this is being overridden by my wifi interface on which I don't know how to act, what to configure to make it work with my preferred DNS entries.
For the sake of completeness I also did this to make sure the web browser was relying on a fresh DNS cache without throwing DNS_*
errors (I am not sure this is correct/needed, is it?):
# check current DNS cache
resolvectl statistics
# flush DNS cache
resolvectl flush-caches
If I check the bottom of the file /etc/resolv.conf
then I see this:
nameserver 127.0.0.53
options edns0 trust-ad
search lan
I think this DNS trouble might be related to that entry nameserver 127.0.0.53
but I also know that this file /etc/resolv.conf
is generated automatically (and perhaps refreshed automatically) by systemd-resolved.service
where 127.0.0.53
means that the laptop relies on this local IP address for DNS which is managed by systemd-resolved
so I think I shouldn't be manually changing it.
I have this feeling that different programs/commands use different places/layers to figure out the DNS configuration.
Like if somehow I change the resolvectl
/ systemd-resolved.service
settings, then maybe the browser may be reading the DNS config from somewhere else like that /etc/resolv.conf
file or things like /etc/nsswitch.conf
? Is this the case?
I would like to:
- make this command sudo resolvectl dns 3 1.1.1.1 8.8.8.8
PERMANENT (across reboot and across wifi disconnect/connect cycles)
- change all the other config files e.g. /etc/resolv.conf
or /etc/nsswitch.conf
and similar
to rely on my preferred DNS configuration details. How do I do this?
Asked by TPPZ
(637 rep)
Jul 7, 2023, 03:11 PM
Last activity: Jul 13, 2023, 04:33 AM
Last activity: Jul 13, 2023, 04:33 AM