Theme editor

Guide Linux How to Manually Set Static DNS Servers on Ubuntu (Disabling systemd-resolved)

  • Thread starter Thread starter CL4Y
  • Start date Start date
  • Views 297

CL4Y

Keyboard Ninja
Administrator
Thread owner

🌎 How to Manually Set Static DNS Servers on Ubuntu (Disabling systemd-resolved)​

If you've tried to edit /etc/resolv.conf on a modern Ubuntu server (18.04, 20.04, 22.04+), you have likely discovered that your changes are overwritten or ignored after a reboot.

This is not a bug. Modern Ubuntu systems use the systemd-resolved service to dynamically manage network configuration, including DNS. This service controls the /etc/resolv.conf file, which is often just a symlink to a stub file.

To permanently set your own DNS servers, you must first disable this service and then create a static resolv.conf file.

Warning: This procedure will completely disable the systemd-resolved service. This is a common requirement for servers needing a hard-coded DNS setup (e.g., for internal resolvers or policy compliance) but is not recommended without a specific reason.



Step 1: Disable and Stop systemd-resolved​

First, you must stop the systemd-resolved service from running and prevent it from starting again on the next boot.

Execute the following commands:
Bash:
sudo systemctl disable systemd-resolved.service
sudo systemctl stop systemd-resolved

jetto-ubuntu-systemd-resolved-disable-1.gif




Step 2: Remove the Existing resolv.conf Symlink​

The /etc/resolv.conf file on your system is likely a symbolic link pointing to a file managed by systemd. We must remove this link before we can create a real file in its place.
Bash:
sudo rm /etc/resolv.conf

jetto-ubuntu-systemd-resolved-disable-2.gif




Step 3: Create a New Static resolv.conf​

With the service disabled and the symlink gone, you can now create a new, static resolv.conf file. We will use nano to edit the file.
Bash:
sudo nano /etc/resolv.conf

Inside the text editor, add the nameserver lines for the DNS providers you wish to use. For this example, we will use Cloudflare's public DNS servers:
Bash:
nameserver 1.1.1.1
nameserver 1.0.0.1
(Save the file and exit nano by pressing CTRL + X, then Y, then Enter).

jetto-ubuntu-systemd-resolved-disable-3.gif




Step 4: Verify DNS Resolution with nslookup​

With the new configuration applied, you must verify that your system is correctly using the new DNS servers to resolve domains.

The nslookup utility is the standard tool for this.

Test the resolution by querying a public domain:
Bash:
nslookup google.com
The output should show you which server handled your request. It should match one of the IPs you just set in /etc/resolv.conf (e.g., 1.1.1.1), confirming that your static configuration is active and working correctly.

jetto-ubuntu-systemd-resolved-disable-4.gif
 
Back
Top