How to Fix ‘Could Not Resolve Host’ cURL Error in Ubuntu

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:

  1. Check service status:
    sudo systemctl status systemd-resolved
  2. Restart the service:
    sudo systemctl restart systemd-resolved
  3. Verify that the service is running and enabled on boot:
    sudo systemctl enable systemd-resolved
  4. 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:

  1. Check the status of /etc/resolv.conf:
    ls -l /etc/resolv.conf
  2. 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
  3. 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:

  1. Open your Netplan configuration file:
    sudo nano /etc/netplan/01-netcfg.yaml
  2. Under your active interface (e.g. eth0 or enp3s0), add the nameservers block:
    network:
      version: 2
      renderer: networkd
      ethernets:
        eth0:
          dhcp4: true
          nameservers:
            addresses: [1.1.1.1, 8.8.8.8]
  3. Save the file and apply the configuration:
    sudo netplan apply
  4. Test cURL again:
    curl -I https://digitash.com
    The HTTP response headers will now return successfully.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.