Setting DNS servers on Ubuntu 26.04 is essential for proper network name resolution. Whether you are configuring a server or desktop system, Ubuntu provides multiple methods to set DNS servers depending on your network management backend. This guide covers how to set DNS on Ubuntu 26.04 using Netplan for servers and NetworkManager for desktops, with practical examples for each approach.
Software Requirements and Linux Command Line Conventions
Category
Requirements, Conventions or Software Version Used
System
Ubuntu 26.04 Resolute Raccoon
Software
Netplan or NetworkManager (installed by default)
Other
Privileged access to your Linux system as root or via the sudo command.
Conventions
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command $ – requires given linux commands to be executed as a regular non-privileged user
To set DNS on Ubuntu 26.04, edit your Netplan configuration file and add the nameservers directive, then apply the changes.
Quick Steps to Set DNS on Ubuntu 26.04
Step
Command/Action
1. Edit Netplan config
sudo nano /etc/netplan/00-installer-config.yaml
2. Add nameservers section
nameservers: addresses: [9.9.9.9, 1.1.1.1]
3. Apply configuration
sudo netplan apply
4. Verify DNS
resolvectl status
PRIVACY-FOCUSED DNS PROVIDERS
This guide uses privacy-respecting DNS providers in all examples. Quad9 (9.9.9.9, 149.112.112.112) is a non-profit based in Switzerland that includes malware blocking. Cloudflare (1.1.1.1, 1.0.0.1) offers fast resolution with independently audited privacy policies. Mullvad (194.242.2.2) provides a strict no-logging policy. All three support DNS over TLS and DNS over HTTPS for encrypted queries.
Check Current DNS Configuration
Before making changes, you should check your current DNS settings on Ubuntu 26.04. The resolvectl command provides detailed information about your DNS configuration, including which DNS servers are currently active and which interface they are associated with.
View DNS status: Run the following command to display your current DNS configuration:
$ resolvectl status
This command shows the DNS servers for each network interface, along with the current DNS resolution settings. Look for the “DNS Servers” line under your active interface.
Check resolv.conf: You can also examine the traditional resolver configuration file:
$ cat /etc/resolv.conf
On Ubuntu 26.04, this file is typically a symlink managed by systemd-resolved. The nameserver entry usually points to 127.0.0.53 (the local stub resolver) or may show a DNS server provided by DHCP, such as your ISP’s DNS or a private DNS server on your network.
Netplan is the default network configuration tool on Ubuntu Server 26.04. To set DNS servers using Netplan, you need to modify the YAML configuration file and add the nameservers directive. This method is recommended for static IP configurations and server deployments where direct control over network settings is required.
Identify your Netplan configuration file: List the files in the Netplan directory:
$ ls /etc/netplan/
Common filenames include 00-installer-config.yaml (Ubuntu Server default), 01-netcfg.yaml, or 50-cloud-init.yaml (cloud deployments) depending on your installation method.
Edit the Netplan configuration: Open the configuration file with a text editor:
$ sudo nano /etc/netplan/00-installer-config.yaml
Add or modify the nameservers section under your network interface. Here is a complete example using static IP with custom DNS:
# This is the network config written by 'subiquity'
network:
version: 2
ethernets:
ens18:
addresses:
- 172.16.1.170/24
routes:
- to: default
via: 172.16.1.1
nameservers:
addresses:
- 9.9.9.9
- 149.112.112.112
search:
- example.com
match:
macaddress: bc:24:11:5e:a0:5f
set-name: ens18
The addresses field specifies the DNS servers to use (this example uses Quad9, a privacy-focused DNS provider), while the optional search field defines the domain search list for short hostnames. The match and set-name directives ensure consistent interface naming based on MAC address.
If you use DHCP for IP assignment but want to specify your own DNS servers, use this configuration:
# This is the network config written by 'subiquity'
network:
version: 2
ethernets:
ens18:
dhcp4: true
dhcp6: true
nameservers:
addresses:
- 1.1.1.1
- 1.0.0.1
search:
- example.com
match:
macaddress: bc:24:11:5e:a0:5f
set-name: ens18
This configuration obtains the IP address, gateway, and other network parameters from DHCP while using your manually specified DNS servers (Cloudflare in this example) instead of those provided by the DHCP server.
Validate the configuration: Before applying changes, test the configuration for syntax errors:
$ sudo netplan try
This command applies the configuration temporarily and reverts automatically after 120 seconds if you do not confirm. This prevents lockouts from configuration mistakes.
Apply the configuration: Once validated, apply the changes permanently:
$ sudo netplan apply
IMPORTANT
If your system uses DHCP, you can still override the DNS servers provided by DHCP by adding the nameservers section to your Netplan configuration. The manually specified DNS servers will take precedence.
Set DNS on Ubuntu 26.04 with NetworkManager (Desktop)
Ubuntu Desktop uses NetworkManager for network configuration. You can set DNS servers through the graphical interface or using the nmcli command-line tool. On Ubuntu 26.04 Desktop, NetworkManager manages network connections with names prefixed by netplan- (e.g., netplan-ens18). This approach is ideal for desktop users who want to configure network settings without editing configuration files directly.
Using the Graphical Interface
Open Network Settings: Click the network icon in the system tray and select “Settings” or navigate to Settings > Network.
Edit your connection: Click the gear icon next to your active connection to open the connection settings.
Configure DNS: Go to the IPv4 (or IPv6) tab. Change the “DNS” toggle from Automatic to Manual, then enter your preferred DNS servers separated by commas (e.g., 9.9.9.9, 1.1.1.1).
After configuring DNS on Ubuntu 26.04, you should verify that name resolution works correctly with your new DNS servers.
Check active DNS servers: Confirm which DNS servers are currently in use:
$ resolvectl status
Look for your configured DNS servers under the appropriate interface or global section.
Test DNS resolution: Verify that DNS queries resolve correctly:
$ resolvectl query ubuntu.com
This command queries the DNS server and displays the resolved IP address along with the DNS server that provided the answer.
Test with dig: For more detailed DNS testing, use the dig command:
$ dig ubuntu.com
The output shows the query result, response time, and the DNS server used. If dig is not installed, install it with sudo apt install dnsutils.
TROUBLESHOOTING
If DNS resolution fails after configuration changes, verify that your DNS servers are reachable with ping 1.1.1.1. If ping works but DNS does not, check for firewall rules blocking UDP port 53. You can check firewall rules using sudo ufw status.
Conclusion
Setting DNS on Ubuntu 26.04 can be accomplished through different methods depending on your system configuration. For Ubuntu Server, Netplan provides the most straightforward approach by adding the nameservers directive to your network configuration. Desktop users can use NetworkManager through the GUI or nmcli commands. After making changes, always verify your configuration using resolvectl status and test actual DNS resolution to confirm everything works as expected.
Frequently Asked Questions
Why does /etc/resolv.conf show 127.0.0.53 as the nameserver? On Ubuntu 26.04, systemd-resolved manages DNS resolution and runs a local DNS stub resolver on 127.0.0.53. This is normal behavior. Your actual configured DNS servers are used by systemd-resolved behind the scenes. Use resolvectl status to see the real DNS servers in use.
How do I prevent DHCP from overwriting my DNS settings? When using Netplan, add your DNS servers in the nameservers section and they will take precedence over DHCP-provided servers. With NetworkManager, set ipv4.ignore-auto-dns yes on your connection to ignore DNS servers from DHCP.
Which DNS provider should I choose for privacy? For privacy, consider Quad9 (9.9.9.9) which is a non-profit with built-in malware blocking, Cloudflare (1.1.1.1) which offers fast speeds with audited privacy practices, or Mullvad (194.242.2.2) for the strictest no-logging policy. All three are better privacy choices than default ISP DNS servers, which often log your queries.
What is the difference between Netplan and NetworkManager for DNS configuration? Netplan is the default network configuration tool on Ubuntu Server and uses YAML configuration files. NetworkManager is the default on Ubuntu Desktop and provides both GUI and command-line (nmcli) interfaces. Use Netplan for servers and NetworkManager for desktops.