How to Change DNS Servers on a VPS: Linux, Windows

12 Jan 2026 By Edgars Kalējs

To change DNS on a server, first work out what actually controls name resolution: a plain /etc/resolv.conf, systemd-resolved, netplan or NetworkManager on Linux, or Set-DnsClientServerAddress on Windows. Editing the wrong file usually gets silently reverted — each case is covered below.

Find out what manages DNS on your system

Start by checking where resolv.conf points:

ls -l /etc/resolv.conf
  • If it is a symlink to ../run/systemd/resolve/stub-resolv.conf, DNS is managed by systemd-resolved.
  • If it is a regular file, you can edit it directly — though netplan, NetworkManager or cloud-init may still overwrite it.

Method 1. Editing resolv.conf directly

This works when no service owns the file. Open it:

sudo nano /etc/resolv.conf

Set the servers you want:

nameserver 1.1.1.1
nameserver 8.8.8.8

Downside: the file can be overwritten on reboot. For a permanent change, use the method that matches your network manager.

Method 2. systemd-resolved

Edit the service config:

sudo nano /etc/systemd/resolved.conf

In the [Resolve] section set:

[Resolve]
DNS=1.1.1.1 8.8.8.8
FallbackDNS=9.9.9.9

Restart the service and check the result:

sudo systemctl restart systemd-resolved
resolvectl status

Method 3. netplan (Ubuntu)

If the network is configured through netplan, DNS belongs there:

network:
  version: 2
  ethernets:
    ens3:
      nameservers:
        addresses:
          - 1.1.1.1
          - 8.8.8.8

Apply it:

sudo netplan apply

Method 4. Windows Server

In an elevated PowerShell, find the interface index and set the DNS servers:

Get-NetAdapter | Format-Table Name, ifIndex
Set-DnsClientServerAddress -InterfaceIndex 12 -ServerAddresses ("1.1.1.1","8.8.8.8")

Verify:

Get-DnsClientServerAddress -InterfaceIndex 12
Provider Primary Secondary
Cloudflare 1.1.1.1 1.0.0.1
Google 8.8.8.8 8.8.4.4
Quad9 9.9.9.9 149.112.112.112

Method 5. NetworkManager (nmcli)

On CentOS, RHEL, Fedora and some desktop Ubuntu installs, the network is managed by NetworkManager. Change DNS through nmcli, otherwise your resolv.conf edits get reverted.

List the active connections:

nmcli connection show

Set DNS for the connection you need (for example System eth0):

sudo nmcli connection modify "System eth0" ipv4.dns "1.1.1.1 8.8.8.8"
sudo nmcli connection modify "System eth0" ipv4.ignore-auto-dns yes
sudo nmcli connection up "System eth0"

The ignore-auto-dns yes option stops DHCP-supplied servers from overwriting yours.

Flushing the DNS cache

After switching resolvers, old answers may still sit in the cache. Flush it:

sudo resolvectl flush-caches

On Windows:

Clear-DnsClientCache

How to confirm the DNS change

resolvectl status
dig example.com
nslookup example.com

In the dig output, the SERVER: line shows which resolver was actually used.

Frequently asked questions

Why does resolv.conf revert after a reboot? It is rewritten by systemd-resolved, netplan or cloud-init. Change DNS in whichever component owns the file, not in resolv.conf itself.

Do DNS changes apply instantly? For new queries, yes. Answers already cached live until their TTL expires. Flush with sudo resolvectl flush-caches.

How do I choose a DNS server? Go by proximity and reliability: Cloudflare (1.1.1.1) and Google (8.8.8.8) are fast and stable in most regions.

Can I point the server at my own local resolver? Yes — put the IP of your resolver (for example unbound or dnsmasq) in nameserver/DNS=.

How do I see which DNS server is in use right now? resolvectl status on Linux or Get-DnsClientServerAddress on Windows shows the active servers.

Setting up and running your own server? Take a Linux VPS in the VPS hosting section or order server administration.

Edgars Kalējs