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:
- Open Settings and go to Network & internet (on Windows 10: Start, Settings, Network & internet).
- For Wi-Fi, select Wi-Fi, Manage known networks and the network. For a cable, select Ethernet and the connected network.
- Next to IP assignment, select Edit.
- Under Edit IP settings, choose Manual and turn on IPv4.
- 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.
- 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)
- Press Win+R, type
ncpa.cpland press Enter to open Network Connections. - Right-click the adapter and select Properties.
- Select Internet Protocol Version 4 (TCP/IPv4) and click Properties.
- 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.
- 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
- See what you use now:
resolvectl dns
/etc/resolv.confshowsnameserver 127.0.0.53on Ubuntu: that is the local systemd-resolved stub, not your real DNS server. - Open the YAML file in
/etc/netplan/(often50-cloud-init.yaml). On a server with a static IP, putnameserversunder 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, adddhcp4-overrides: use-dns: falseso 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] - Test with a safety net:
sudo netplan tryapplies the change and rolls it back after 120 seconds unless you confirm it (netplan documentation). Then make it permanent withsudo netplan apply. - Check:
resolvectl dnsshould 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.cfgcontainingnetwork: {config: disabled}. - Netplan warns
Permissions for /etc/netplan/50-cloud-init.yaml are too openwhen others can read the file. Fix it withsudo 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
- Web hosting: shared hosting on Virtualmin with NVMe storage, free SSL and email.
- SSL certificates: DV, OV and wildcard, with free installation help.
- Reseller hosting: white-label cPanel hosting for your own clients.
