Updated: 11 October 2026 · Applies to: Ubuntu 26.04 (netplan 1.2, systemd 259) and 24.04 (netplan 1.1.2), AlmaLinux 10 (NetworkManager 1.56) and 9, Debian 13, tested in containers; Windows 10, Windows 11 and Windows Server 2016 to 2025 from Microsoft’s documentation

To change your DNS server, you change which resolver the computer asks to turn names into IP addresses. On Windows, open Settings, Network & internet, your connection, then Edit next to IP assignment and fill in Preferred DNS and Alternate DNS, or run one PowerShell line as administrator: Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ServerAddresses ("1.1.1.1","9.9.9.9"). On Ubuntu Server, add nameservers to the netplan file and run sudo netplan apply. This is not the same as changing your domain’s nameservers; for that, see what a nameserver is and how to change it.

Before you change anything

  • Which servers: your provider’s resolvers, or public ones such as Cloudflare (1.1.1.1, 1.0.0.1), Google (8.8.8.8, 8.8.4.4) or Quad9 (9.9.9.9, 149.112.112.112). Always set two.
  • Active Directory: Microsoft recommends that computers joined to a domain use DNS servers that host the domain’s zone, normally the domain controllers, and not an internet provider’s resolvers. Public resolvers go into the DNS server’s forwarders instead.
  • Remote servers: a typo in the network file can cut you off. Keep the VPS console open while you work: access your VPS through VNC.

Windows 10 and 11: change DNS in Settings

According to Microsoft:

  1. Open Settings and go to Network & internet (on Windows 10: Start, Settings, Network & internet).
  2. For Wi-Fi, select Wi-Fi, Manage known networks and the network. For a cable, select Ethernet and the connected network.
  3. Next to IP assignment, select Edit.
  4. Under Edit IP settings, choose Manual and turn on IPv4.
  5. Type the servers in Preferred DNS and Alternate DNS. On Windows 11 you can also choose DNS over HTTPS here; Microsoft notes that Windows 10 does not have this setting.
  6. Select Save.

Manual in this dialog means you also type the IP address, subnet mask and gateway. If the computer gets its address from DHCP and you only want other DNS servers, use the Control Panel or PowerShell method below.

Windows: Control Panel (keeps DHCP for the address)

  1. Press Win+R, type ncpa.cpl and press Enter to open Network Connections.
  2. Right-click the adapter and select Properties.
  3. Select Internet Protocol Version 4 (TCP/IPv4) and click Properties.
  4. Leave Obtain an IP address automatically as it is, select Use the following DNS server addresses and fill in Preferred DNS server and Alternate DNS server.
  5. Click OK, then close the adapter properties window. Repeat with Internet Protocol Version 6 (TCP/IPv6) if you use IPv6 DNS servers.

These are the dialog names from Microsoft’s TCP/IP settings procedure. Windows does not ask every server for each lookup: Microsoft explains that it uses the preferred server and switches to the alternate only when the preferred one stops answering.

Windows Server: PowerShell, netsh and SConfig

In PowerShell as administrator (from Microsoft’s cmdlet reference):

Get-DnsClientServerAddress
Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ServerAddresses ("1.1.1.1","9.9.9.9")
Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ResetServerAddresses

Replace Ethernet with your adapter name from the first command. Microsoft notes that addresses set this way override the ones from DHCP; -ResetServerAddresses goes back to DHCP.

In Command Prompt as administrator, Microsoft’s netsh syntax is:

netsh interface ipv4 set dnsservers name="Ethernet" source=static address=1.1.1.1 register=primary
netsh interface ipv4 add dnsservers name="Ethernet" address=9.9.9.9 index=2
netsh interface ipv4 show dnsservers name="Ethernet"
netsh interface ipv4 set dnsservers name="Ethernet" source=dhcp

On Server Core, SConfig does the same: type 8 (Network settings), pick the adapter number, then 2 to set the preferred and alternate DNS server (3 clears them). Microsoft notes SConfig starts automatically on Server Core from Windows Server 2022 and needs a local administrator. Running Windows on a Ucartz VPS? See connect to a Windows VPS with Remote Desktop.

Ubuntu Server: set DNS servers with netplan

  1. See what you use now:
    resolvectl dns
    /etc/resolv.conf shows nameserver 127.0.0.53 on Ubuntu: that is the local systemd-resolved stub, not your real DNS server.
  2. Open the YAML file in /etc/netplan/ (often 50-cloud-init.yaml). On a server with a static IP, put nameservers under the interface:
    network:
      version: 2
      ethernets:
        eth0:
          addresses:
            - 203.0.113.10/24
          routes:
            - to: default
              via: 203.0.113.1
          nameservers:
            addresses: [1.1.1.1, 9.9.9.9]
            search: [example.com]
    With DHCP, add dhcp4-overrides: use-dns: false so the DHCP server’s resolvers are not added as well (the interface part of the file):
        eth0:
          dhcp4: true
          dhcp4-overrides:
            use-dns: false
          nameservers:
            addresses: [1.1.1.1, 9.9.9.9]
  3. Test with a safety net: sudo netplan try applies the change and rolls it back after 120 seconds unless you confirm it (netplan documentation). Then make it permanent with sudo netplan apply.
  4. Check: resolvectl dns should list the new servers for the interface.

Lab example, Ubuntu 26.04 (netplan 1.2): netplan generate turned the static file into a systemd-networkd file with DNS=1.1.1.1, DNS=9.9.9.9 and Domains=example.com; the DHCP version also got UseDNS=false. Things to watch:

  • If the file starts with This file is generated from information provided by the datasource., cloud-init owns it and can overwrite it. The header itself explains how to stop that: a file /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg containing network: {config: disabled}.
  • Netplan warns Permissions for /etc/netplan/50-cloud-init.yaml are too open when others can read the file. Fix it with sudo chmod 600 /etc/netplan/*.yaml.
  • Server lists from several netplan files are added together, so remove old entries rather than adding a second file.

Full static IP walkthrough: static IP on Ubuntu with Netplan.

Ubuntu: temporary and global changes with systemd-resolved

sudo resolvectl dns eth0 192.0.2.53 198.51.100.53   # this interface, until reboot
sudo resolvectl revert eth0                          # undo

In our test the setting survived a restart of systemd-resolved but was only stored under /run (a memory file system), not in any configuration file, so it does not survive a reboot. Use it to try a resolver, then make the change in netplan.

To set DNS servers for the whole machine instead of one interface, create /etc/systemd/resolved.conf.d/dns.conf (the drop-in folder that resolved.conf itself recommends):

[Resolve]
DNS=1.1.1.1 9.9.9.9

Then run sudo systemctl restart systemd-resolved. Lab output on Ubuntu 26.04:

$ resolvectl dns
Global: 1.1.1.1 9.9.9.9
Link 2 (eth0):

As the comment in resolved.conf says, global servers do not switch off the per-interface ones, so on a DHCP server also set use-dns: false in netplan.

AlmaLinux, Rocky Linux and RHEL: NetworkManager

nmcli connection show
sudo nmcli connection modify eth0 ipv4.dns "1.1.1.1 9.9.9.9" ipv4.ignore-auto-dns yes
sudo nmcli connection up eth0

Use the connection name from the first command. With nmcli 1.56 on AlmaLinux 10 the saved profile contained dns=1.1.1.1;9.9.9.9; and ignore-auto-dns=true. For IPv6, use ipv6.dns and ipv6.ignore-auto-dns. More examples: set a static IP from the command line.

Debian with ifupdown

If the resolvconf package is installed, add dns-nameservers 1.1.1.1 9.9.9.9 to the interface in /etc/network/interfaces. Without it, edit /etc/resolv.conf directly:

nameserver 1.1.1.1
nameserver 9.9.9.9

Full example: static IP on Debian 13. If you see resolvconf: Error: /etc/resolv.conf isn’t a symlink, see this fix.

Check the result

$ dig @1.1.1.1 example.com A | grep SERVER
;; SERVER: 1.1.1.1#53(1.1.1.1) (UDP)
$ nslookup example.com 9.9.9.9 | head -2
Server:		9.9.9.9
Address:	9.9.9.9#53

On AlmaLinux and Debian, the SERVER line of dig example.com (without @) shows the server the system uses now; on Ubuntu it shows the local stub 127.0.0.53, so use resolvectl dns there. On Windows, run ipconfig /all or nslookup example.com. Old answers can stay cached for a while after the switch: clear the DNS cache.

Official documentation: Microsoft: change TCP/IP settings, Set-DnsClientServerAddress and netplan try.

Ucartz services for this topic

Was this answer helpful? 0 Users Found This Useful (0 Votes)