When you type example.com into a browser, the computer has to turn that name into an IP address before it can connect.
Turning a name into an address is called name resolution and is handled by the DNS system. When "the network is up but I can't reach websites", it is very often a DNS problem.
This article explains how an Ubuntu 24.04 LTS machine looks up DNS, and how to use resolvectl to inspect, test and diagnose it.
If your machine does not yet have the right address and DNS servers, review how to declare addresses and DNS in netplan before diagnosing further.
On Ubuntu, the systemd-resolved service acts as the name resolver for the whole machine.
Programs do not ask a remote DNS server themselves; they ask a "middleman" running right on the machine at the address 127.0.0.53. This middleman:
keeps a cache, so names looked up recently are answered faster;
knows which DNS server belongs to which network interface (for example the DNS of your home network and the DNS of a VPN);
forwards the question to the real DNS servers, taken from DHCP or from the netplan configuration.
That is why, when you open /etc/resolv.conf, you usually see only the line nameserver 127.0.0.53.
That is not an error: this file is a link to /run/systemd/resolve/stub-resolv.conf, and the list of real DNS servers lives elsewhere. To see them, use resolvectl.
resolvectl status
The output is split into a global part (Global) and each network interface (Link). For each interface you will see information such as:
Current DNS Server: the DNS server currently in use.
DNS Servers: the list of servers that can be used.
DNS Domain: the search domain.
To view just one interface, add the interface name: resolvectl status enp1s0. This is the first step when you suspect DNS: is the DNS server what you think it is?
resolvectl query example.com
The command prints the addresses it found, and tells you which protocol was used and which network interface answered.
If an address came from the cache, the result also states the data source as the cache. Run it twice in a row and you will see the difference between a fresh query and one served from the cache.
You can ask for a specific record type, for example a mail record (MX) or IPv6 (AAAA):
resolvectl query --type=MX example.com
resolvectl query --type=AAAA example.com
You don't need to remember all the options; see resolvectl --help or man resolvectl when needed.
If you want to ask one specific DNS server directly for comparison, install the bind9-dnsutils package and then use dig:
sudo apt install bind9-dnsutils
dig @192.0.2.53 example.com
The @ sign specifies the server to ask. If dig answers correctly but resolvectl query is wrong, the problem most likely lies in the configuration on your machine, not in the DNS server.
You can assign a DNS server to a network interface without editing a configuration file:
sudo resolvectl dns enp1s0 192.0.2.53
sudo resolvectl domain enp1s0 example.com
This change only lasts until the network is reconfigured or the machine restarts. To drop it right away, run:
sudo resolvectl revert enp1s0
To change it permanently, edit the nameservers entry in the netplan file in netplan and then apply it.
When you have just edited a DNS record but the machine still returns the old address, clear the cache:
sudo resolvectl flush-caches
The resolvectl statistics command shows the number of cache hits, the number of queries sent, and the overall state of the service.
The /etc/systemd/resolved.conf file holds global settings, for example the list of fallback DNS servers (FallbackDNS) or DNSSEC. The lines in the default file are usually commented out with #.
After editing, restart the service:
sudo systemctl restart systemd-resolved
Warning: a wrong DNS configuration can leave the whole machine unable to resolve any name. Back up the file before editing and keep a spare login session open.
resolvectl status: is it the right DNS server yet?
resolvectl query example.com: can it look the name up?
If not, try calling the IP address directly with ping. If pinging the IP works but pinging the name does not, the fault is in DNS, not in the connection.
dig @<server> example.com: does the DNS server answer?
sudo resolvectl flush-caches and then try again.
The connection-checking steps in item 3 are explained in Checking network connectivity on Ubuntu with ip, ss, ping and tracepath.
On Ubuntu 24.04, systemd-resolved is the name resolver for the whole machine, listening at 127.0.0.53.
Use resolvectl status to see the real DNS servers, resolvectl query to test a name lookup, resolvectl flush-caches to clear the cache, and make lasting DNS changes in the netplan configuration.
Ubuntu Server, DNS: https://documentation.ubuntu.com/server/how-to/networking/install-dns/
The man page for resolvectl: https://manpages.ubuntu.com/manpages/noble/en/man1/resolvectl.1.html
The man page for systemd-resolved: https://manpages.ubuntu.com/manpages/noble/en/man8/systemd-resolved.service.8.html
Wikipedia, Domain Name System: https://en.wikipedia.org/wiki/Domain_Name_System