The curl command is an indispensable utility on Ubuntu for downloading software repositories, testing REST APIs, and automating deployment scripts. However, running a standard request (such as curl -I https://api.example.com) frequently halts with the immediate error: curl: (6) Could not resolve host: api.example.com or wget: unable to resolve host address.
cURL Error 6 is a strict DNS resolution failure. It indicates that the operating system network stack was unable to query your configured Domain Name System (DNS) nameservers to translate the requested domain into an IP address. This fault is predominantly triggered by misconfigured symlinks in /etc/resolv.conf, a stalled systemd-resolved daemon, or stale nameserver entries in Netplan. Follow this guide to resolve host resolution faults in Ubuntu.
Test DNS Resolution with dig and nslookup
Before adjusting configuration files, verify whether DNS resolution is failing globally across all tools or exclusively inside specific terminal scripts:
dig example.com +short
nslookup example.com
If both commands return timeout errors or state “;; connection timed out; no servers could be reached”, your system cannot communicate with any configured nameserver.
Restart and Re-enable systemd-resolved
On Ubuntu 20.04 LTS, 22.04 LTS, and 24.04 LTS, local DNS resolution is managed by the systemd-resolved service. If this daemon hangs, all hostname queries stall:
- Check service status:
sudo systemctl status systemd-resolved - Restart the service:
sudo systemctl restart systemd-resolved - Verify that the service is running and enabled on boot:
sudo systemctl enable systemd-resolved - Flush the internal DNS cache:
sudo resolvectl flush-caches
Repair the /etc/resolv.conf Symbolic Link
In Ubuntu, /etc/resolv.conf must be a symbolic link pointing to the systemd stub resolver file. If third-party software or an administrator created a static file that became corrupted, resolution breaks:
- Check the status of
/etc/resolv.conf:ls -l /etc/resolv.conf - If it is not a symlink pointing to
/run/systemd/resolve/stub-resolv.conf, delete the broken file and recreate the proper link:sudo rm /etc/resolv.conf sudo ln -s /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf - Restart the resolved daemon:
sudo systemctl restart systemd-resolved
Add Static Fallback Nameservers via Netplan
If your local DHCP router fails to supply valid DNS resolvers, configure public upstream fallback nameservers (such as Google or Cloudflare) in your Netplan configuration:
- Open your Netplan configuration file:
sudo nano /etc/netplan/01-netcfg.yaml - Under your active interface (e.g.
eth0orenp3s0), add thenameserversblock:network: version: 2 renderer: networkd ethernets: eth0: dhcp4: true nameservers: addresses: [1.1.1.1, 8.8.8.8] - Save the file and apply the configuration:
sudo netplan apply - Test cURL again:
The HTTP response headers will now return successfully.curl -I https://digitash.com