> ## Documentation Index
> Fetch the complete documentation index at: https://help.freakhosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Change DNS Server on Linux (resolv.conf, systemd-resolved)

> Change the DNS server on Linux: set nameservers in Netplan on Ubuntu (systemd-resolved), nmcli ipv4.dns on AlmaLinux/Rocky, or edit resolv.conf on Debian.

To change the DNS server on Linux, change it where your network tool stores it rather than editing `/etc/resolv.conf` by hand. On Ubuntu, set `nameservers: addresses: [1.1.1.1, 9.9.9.9]` in your Netplan file and run `sudo netplan apply`; systemd-resolved then uses them. On AlmaLinux/Rocky, run `sudo nmcli connection modify "System eth0" ipv4.dns "1.1.1.1 9.9.9.9" ipv4.ignore-auto-dns yes`. Check with `resolvectl status` or `cat /etc/resolv.conf`.

| Difficulty | Time | Works on | Needs |
| - | - | - | - |
| Beginner | 5 minutes | Ubuntu 22.04/24.04, Debian 12/13, AlmaLinux/Rocky 9/10 | sudo access |

## Before you start

* A **DNS resolver** turns names like `example.com` into IP addresses. Your server asks the resolvers listed in its network settings.
* On a VPS you can also pick resolvers in the panel: see [change your VPS's DNS resolvers](https://help.freakhosting.com/portals/vps-panel/how-to-change-ipv4-public-dns-resolvers.md). Whether the panel setting reaches the server depends on how its network is configured; the steps below change it inside the server.
* Commands use `sudo`; as root, leave it out.

## Which method applies to my server?

```bash theme={null}
ls -l /etc/resolv.conf
```

| Output | What manages DNS | Use |
| - | - | - |
| A link to `/run/systemd/resolve/stub-resolv.conf` | systemd-resolved (Ubuntu default) | **Ubuntu** tab |
| File mentions `Generated by NetworkManager` | NetworkManager | **AlmaLinux / Rocky** tab |
| A plain file you can edit | Nothing, or ifupdown | **Debian (static file)** tab |

On Ubuntu, `/etc/resolv.conf` lists `nameserver 127.0.0.53`. That's systemd-resolved's local stub, which forwards queries to your real resolvers. Don't replace it.

## How to change the DNS server

> [tab] Ubuntu (Netplan + systemd-resolved)
>
> **1. Edit the Netplan file**
>
> ```bash theme={null}
> sudo nano /etc/netplan/50-cloud-init.yaml
> ```
>
> Set the resolvers under your interface:
>
> ```yaml theme={null}
> network:
>   version: 2
>   ethernets:
>     eth0:
>       dhcp4: true
>       dhcp4-overrides:
>         use-dns: false
>       nameservers:
>         addresses: [1.1.1.1, 9.9.9.9]
> ```
>
> `use-dns: false` stops DHCP from adding its own resolvers. With a static setup (`dhcp4: false`), you only need `nameservers`.
>
> **2. Apply**
>
> ```bash theme={null}
> sudo netplan try
> ```
>
> Press **Enter** to keep the change.
>
> **3. Check**
>
> ```bash theme={null}
> resolvectl status eth0
> ```
>
> **DNS Servers** should list `1.1.1.1 9.9.9.9`.
>
> To try a resolver without changing files (lost at reboot or next network change), use `sudo resolvectl dns eth0 1.1.1.1 9.9.9.9`, and undo it with `sudo resolvectl revert eth0`.

> [tab] AlmaLinux / Rocky (NetworkManager)
>
> **1. Find the connection name**
>
> ```bash theme={null}
> nmcli connection show
> ```
>
> **2. Set the DNS servers**
>
> ```bash theme={null}
> sudo nmcli connection modify "System eth0" ipv4.dns "1.1.1.1 9.9.9.9" ipv4.ignore-auto-dns yes
> ```
>
> `ipv4.ignore-auto-dns yes` stops DHCP-provided resolvers being added.
>
> **3. Apply**
>
> ```bash theme={null}
> sudo nmcli connection up "System eth0"
> ```
>
> **4. Check**
>
> ```bash theme={null}
> cat /etc/resolv.conf
> ```
>
> NetworkManager writes the new `nameserver` lines there.

> [tab] Debian (static file)
>
> If `/etc/resolv.conf` is a normal file and no tool manages it, edit it directly:
>
> ```bash theme={null}
> sudo nano /etc/resolv.conf
> ```
>
> ```ini theme={null}
> nameserver 1.1.1.1
> nameserver 9.9.9.9
> ```
>
> The change takes effect straight away. If your Debian server uses Netplan (`ls /etc/netplan/` shows files), use the Ubuntu method instead, or your edit is overwritten.

> [!WARNING]
>
> Don't delete the `/etc/resolv.conf` symlink or replace it with a static file on Ubuntu unless you also disable systemd-resolved. Otherwise name resolution breaks, and the server can't install updates or reach APIs by name.

## How to set DNS for the whole system with systemd-resolved

To use the same resolvers on every interface, create a drop-in file. Files in `/etc/systemd/resolved.conf.d/` override the main file:

```bash theme={null}
sudo mkdir -p /etc/systemd/resolved.conf.d
sudo nano /etc/systemd/resolved.conf.d/dns.conf
```

```ini theme={null}
[Resolve]
DNS=1.1.1.1 9.9.9.9
```

```bash theme={null}
sudo systemctl restart systemd-resolved
```

Per-interface resolvers (from Netplan or DHCP) are still used alongside these. To use only the global servers, remove the interface resolvers as shown in the Ubuntu tab.

## How to check it worked

```bash theme={null}
resolvectl query example.com     # Ubuntu with systemd-resolved
dig example.com +short            # any distribution, needs dnsutils / bind-utils
```

`dig` also shows which server answered: run `dig example.com` and look at the `SERVER:` line. Install it with `sudo apt install bind9-dnsutils` (Ubuntu/Debian) or `sudo dnf install bind-utils` (AlmaLinux/Rocky).

## Frequently asked questions

### Why does my change to /etc/resolv.conf disappear?

A tool regenerates the file: systemd-resolved, NetworkManager, cloud-init or DHCP. Change DNS in that tool instead, as shown above.

### What is 127.0.0.53 in resolv.conf?

The local systemd-resolved stub resolver. Programs ask it, and it forwards to the resolvers you configured. See them with `resolvectl status`.

### How do I clear the DNS cache on Linux?

On systemd-resolved, run `sudo resolvectl flush-caches`. Other setups usually don't cache locally unless you run a caching service such as `nscd` or `dnsmasq`.

### Which public DNS servers should I use?

Common choices are Cloudflare (`1.1.1.1`, `1.0.0.1`), Quad9 (`9.9.9.9`) and Google (`8.8.8.8`, `8.8.4.4`). Use two from different providers so lookups still work if one fails.

## Related guides

> [card] [VPS and dedicated server guides](https://help.freakhosting.com/portals/other/vps-and-dedicated-server-guides.md)
>
> Every guide in this section.

> [card] [Fix name resolution errors](https://help.freakhosting.com/portals/other/how-to-fix-temporary-failure-in-name-resolution.md)
>
> Temporary failure in name resolution.

> [card] [Static IP with Netplan](https://help.freakhosting.com/portals/other/how-to-configure-a-static-ip-with-netplan.md)
>
> Full Netplan network setup.

> [card] [VPS DNS resolvers](https://help.freakhosting.com/portals/vps-panel/how-to-change-ipv4-public-dns-resolvers.md)
>
> Choose resolvers in the VPS Panel.

> [card] [Point a domain to your server](https://help.freakhosting.com/portals/other/how-to-point-a-domain-to-your-server.md)
>
> Records for your own domain.

***

> [!NOTE]
>
> **Checked against the [Ubuntu Server networking guide](https://ubuntu.com/server/docs/explanation/networking/configuring-networks/), the systemd [resolvectl](https://www.freedesktop.org/software/systemd/man/latest/resolvectl.html) and [resolved.conf](https://www.freedesktop.org/software/systemd/man/latest/resolved.conf.html) manuals and the [Red Hat Enterprise Linux 9 networking guide](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/html/configuring_basic_system_settings/assembly_configuring-and-managing-network-access_configuring-basic-system-settings)** on 4 November 2026; the Netplan example was validated with `netplan generate` on Ubuntu 24.04 LTS. Commands can differ on other distributions or releases.

> [!NOTE]
>
> ### Need Extra Help?
>
> If you encounter any issues, our support team is ready to assist:
>
> * **Live Chat:** Quick assistance via our website.
> * **Support Ticket:** [Open a Ticket](https://freakhosting.com/clientarea/submitticket.php)
> * **Discord:** [Join our Community](https://discord.gg/freakhosting)
> * **Email:** [support@freakhosting.com](mailto:support@freakhosting.com)

> [!TIP]
>
> ### Save on Your Hosting
>
> Ready to upgrade your hosting? Use code **KB20** at checkout for **20% off** your first order!

***

**Last Updated:** November 2026


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.