I need to add a second nameserver. I can do it temporarily in resolve.conf, but I want a solution that sticks after reboot.
The settings GUI has a fillin for DNS when automatic is turned off, but that doesn't seem to do anything.
I need to add a second nameserver. I can do it temporarily in resolve.conf, but I want a solution that sticks after reboot.
The settings GUI has a fillin for DNS when automatic is turned off, but that doesn't seem to do anything.
First Open The Terminal and then Type these Commands:
If you don't have resolvconf already installed do this first:
If you have resolvconf already installed complete from here of if you are completed the installation:
It's a bit unclear what kind of combo fun you are having at the moment.
I assume the setup you are currently having is the default systemd-resolved and probably the DHCP server that you are connecting to refreshing the setup, if you are getting them automatically or just not getting anything at all at the moment.
Anyway, an option to possibly way forward to the issue would be trying to make changes to: /etc/systemd/resolved.conf in the same manner as you did for /etc/resolved.conf
Seems that systemd-resolved would have /etc/systemd/resolved.conf take precedence over all the other places you would be able to add that in.
Also depending on what's setup you can also have references to things in /etc/systemd/resolved.conf.d/ that can be added/ammended with the same outcome as changing in /etc/systemd/resolved.conf. (so best to check there also, to be neat and tidy)
More reference/details on the above:
https://wiki.archlinux.org/title/Systemd-resolved
24.04 - How to find "what" is changing DNS settings in /etc/resolv.conf
https://forum.cloudron.io/topic/12384/no-dns-after-upgrade-ubuntu-22-04-to-24-04/5
There are a few ways to define DNS servers with various tradeoffs between each option. I will also outline how to had a Search Domain.
nm-connection-editor
/etc/systemd/resolved.conf
nmcli
But first off, do not edit
/etc/resolv.conf
. This file is managed by the system, and there is no need to edit it directly. The nameserver defined in this file is127.0.0.53
, which is the local caching stub resolver. This is the first server queried in any search with uplink servers queried only when a query is not in the cache.By default,
/etc/resolv.conf
is a symlink to/run/systemd/resolve/stub-resolv.conf
. If this is no longer the case and it's a static file that you've edited, return to it's default state by running the following commands:Secondly, there is no need to install
resolveconf
. There still might be some use cases, but for your needs, it's totally unnecessary to install an application simply to define another DNS server.NOTE: It sounds like your current networking setup is to acquire an IP address and any DNS servers via DHCP. The following examples to add additional DNS Servers assume DHCP and not statically defined IP addresses.
1. Define DNS servers via the GUI with Network Settings
If you want to assign DNS servers manually instead of acquiring them via DHCP, simply uncheck the "Automatic" box and define them. After hitting apply, they will take affect, but keep in mind that this overrides any DNS servers that have been pushed to you via DHCP. Also, you're unable to define any Search Domains with this method.
As an example:
With "Automatic" checked:
Look at output of
resolvectl
to see the current DNS servers in effect pushed to you via DHCP:After manually configuring DNS servers in the settings panel, click Apply:
Check the output of
resolvectl
to see the changes in effect. Take note that the nameservers pushed to you via DHCP are no longer present.2. Define DNS servers via the GUI using
nm-connection-editor
Open a terminal and run the following command to open
nm-connection-editor
:A window will open. Click on your connection and then click on the gear icon.
Go to the IPV4 Settings tab. Enter any additional DNS servers (separated by a comma) and Search Domains (also separated by a comma). Then click Save.
Close the window, and go back to the terminal. Restart Network Manager with
sudo systemctl restart NetworkManager
and look at the output ofresolvectl
. You'll notice that an additional DNS server has been added to your link along with your custom Search Domain (listed as DNS Domain).3. Define DNS servers and search domains by editing
/etc/systemd/resolved.conf
When defining DNS Servers and Search Domains in
/etc/systemd/resolved.conf
, you're defining Global DNS Servers and Search Domains, which means they are available for all links. If this is acceptable, open a terminal and simply edit the file withsudo nano /etc/systemd/resolved.conf
.To define an additional DNS Server, add the following stanza:
To add a Search Domain, add the following stanza:
After saving and closing, run
sudo systemctl restart systemd-resolved
. Then check the output ofresolvectl
. Notice that there is now a Global DNS Server and Search Domain (listed as DNS Domain) in addition to the DNS Servers pushed to you.4. Define DNS servers by using the command
nmcli
You first need to find the connection name. Use the command
nmcli con
:From the command above, the connection name on my system is
netplan-enp0s3
. Substitute yours for the commands below:To define an additional DNS Server:
To define a Search Domain:
Then restart Network Manager and look at the output of
resolvectl
:Take note that in this instance it added the DNS Server and Search Domain to the specific link and not as a Global setting. Additionally, it retained the DNS servers pushed via DHCP.
If you want to assign multiple DNS Servers and a Search Domain and ignore any DNS Servers pushed to you via DHCP, run the following commands:
Finally, take note that when adding a Search Domain via any method outlined above,
/etc/resolv.conf
will be updated as well to reflect the additional Search Domain: