4

I am experiencing an issue with DNS and to help narrow down the problem, I have been asked to configure my machine's DNS settings manually, only specifying one DNS server instead of the two returned via DHCP, so the server admins can find out whether my problem is only happening on one DNS server or both.

However I have been unable to configure systemd-resolved such that it will manually accept my DNS config.

I tried the following, all of which still sent DNS requests randomly between both servers, even after restarting both systemd-networkd and systemd-resolved:

  • Specifying DNS=1.2.3.4 in the [Resolve] section of /etc/systemd/resolved.conf
  • Specifying DNS=1.2.3.4 in the [Network] section of /etc/systemd/network/eth0.conf (the only file in this folder)
  • Editing /etc/resolv.conf and commenting out one of the servers

None of these changed anything, still resolvectl listed both DNS servers as available and when I performed my tests the DNS queries were split between the two servers instead of using only the one server I had specified.

How can I tell systemd to only use a single DNS server I specify, and not to also use the servers returned via DHCP?

2
  • still struggling with the same problem
    – M0nZDeRR
    Jul 28, 2021 at 0:37
  • @M0nZDeRR I added a new answer, can you try it and let me know if it worked?
    – Malvineous
    Jul 28, 2021 at 7:02

3 Answers 3

2

I haven't tried this but I have since found there is an option to ignore DNS servers coming from the DHCP response. In the systemd .network file, add a DHCP section if it doesn't already exist and use the UseDNS option:

[Network]
DNS=8.8.8.8  # Specify your DNS server manually

[DHCPv4]
UseDNS=no  # Don't use DNS servers from DHCP
3
  • Didn't work for me, neither did andrea.corbellini.name/2020/04/28/ubuntu-global-dns But the DNS= should be in the Resolve section?
    – xeruf
    Aug 26, 2023 at 20:46
  • According to man systemd.network the DNS= option belongs in [Network]. Are you rebooting your machine after making the changes? It's notoriously difficult to test systemd network changes without rebooting (it can be done for most things but it's very easy for it to look like your changes haven't worked, when you've just forgotten to restart one of the systemd subcomponents like systemd-resolved or restarted it before systemd-networkd instead of after, so rebooting is more reliable.)
    – Malvineous
    Aug 27, 2023 at 5:37
  • Actually, it seems to work now, though I am not sure if it was this comment that made it work because I experimented with multiple suggestions. Yeah I usually tested by restarting these services.
    – xeruf
    Sep 3, 2023 at 6:46
1

I don't have enough rep to comment on Malvineous's answer. While his answer is correct, nspawn containers need to name the file 80-container-host0.network to override the system defaults from the host.

From the systemd-nspawn docs:

Note that systemd-networkd.service(8) includes by default a network file /usr/lib/systemd/network/80-container-ve.network matching the host-side interfaces created this way, which contains settings to enable automatic address provisioning on the created virtual link via DHCP, as well as automatic IP routing onto the host's external network interfaces. It also contains /usr/lib/systemd/network/80-container-host0.network matching the container-side interface created this way, containing settings to enable client side address assignment via DHCP. In case systemd-networkd is running on both the host and inside the container, automatic IP communication from the container to the host is thus available, with further connectivity to the external network.

/etc/systemd/network/80-container-host0.network:

# https://www.freedesktop.org/software/systemd/man/systemd.network.html#UseDNS=
#
# Disable adding the DNS from DHCP
#
[Match]
Virtualization=container
Name=host0

[Network]
DHCP=ipv4
DNS=

[DHCPv4]
UseDNS=false
2
-2

If you can set a static IP then you can specify the DNS server. Ask the network admins for a static IP you can use and try that. Do not use just any IP for that, you could easily end up with a duplicate.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .