Wget Could Not Resolve Host: Fixes & Causes
In this article
When you run a wget command and see "could not resolve host," it means wget cannot translate the domain name you gave it into an IP address. This is a DNS (Domain Name System) failure, not a problem with wget itself. The fix usually involves checking your internet connection, your DNS settings, or the URL you typed.
What Does "Could Not Resolve Host" Mean?
Every time you use a domain name like example.com, your computer asks a DNS server to look up the corresponding IP address. The DNS server acts like a phone book for the internet. When wget reports "could not resolve host," it means that lookup failed. The hostname itself might be misspelled, the DNS server might be unreachable, or your system's network configuration might be broken. This error is distinct from connection timeouts or refused connections, which happen after the IP address is already known.
Common Causes of DNS Resolution Failure
Several things can cause this error. The most frequent are:
- Typo in the domain name — a missing dot or a wrong letter makes the name unresolvable.
- No internet connection — if you are offline, DNS queries cannot reach any server.
- DNS server problems — your configured DNS server might be down, slow, or misconfigured.
- Firewall or proxy interference — a firewall can block DNS requests (port 53) or a proxy might not be set correctly.
- Local hosts file entries — a stale or incorrect entry in
/etc/hostscan override DNS. - IPv6 issues — if your system tries IPv6 first and the DNS server only returns IPv4, resolution can fail.
How to Diagnose the Problem
Start by checking if the hostname resolves at all. Use the ping command with a domain you know works, like ping example.com. If that fails, the issue is likely system-wide. Then try nslookup example.com or dig example.com to see what DNS returns. If those tools are not installed, try getent hosts example.com. Compare the output with what you expect. If the hostname resolves with these tools but wget still fails, then the problem is specific to wget's environment — maybe a proxy setting or a configuration file.
Step-by-Step Fixes
Work through these fixes in order, testing wget after each one:
- Check the URL — Confirm the domain is spelled correctly and includes the right top-level domain (like .com or .org). Try opening the same URL in a browser.
- Verify internet connectivity — Run
ping 8.8.8.8(a public IP address). If that works but pinging a domain fails, it is definitely DNS. - Flush DNS cache — On Linux, use
sudo systemd-resolve --flush-cachesorsudo resolvectl flush-caches. On macOS,sudo dscacheutil -flushcache. On Windows,ipconfig /flushdns. - Change DNS servers — Temporarily switch to a public DNS like 8.8.8.8 (Google) or 1.1.1.1 (Cloudflare). On Linux, edit
/etc/resolv.conf(though it may be managed by systemd-resolved). On a router, change the DNS settings there. - Check proxy settings — If you use a proxy, set it explicitly in wget:
wget -e use_proxy=yes -e http_proxy=proxy.example.com:8080 URL. Or unset proxy variables:unset http_proxy https_proxy. - Inspect /etc/hosts — Look for any line that maps the domain to an IP. Remove or correct it if wrong.
- Try wget with the IP address — If you know the server's IP, use
wget --header="Host: example.com" http://192.0.2.1/fileto bypass DNS. This is a diagnostic step, not a permanent fix.
When the Error Is Specific to wget
Sometimes wget fails while other tools work. This usually points to wget's configuration. Check the file ~/.wgetrc for any proxy or dns settings. Also check environment variables like http_proxy and https_proxy — if they point to an unreachable proxy, wget will try to use it and fail. You can override with wget --no-proxy URL or by unsetting the variables. Another possibility is that wget is trying IPv6 first; force IPv4 with wget -4 URL.
Network-Level Issues
If the problem persists across all tools, the issue is likely with your network. Your router might have a broken DNS configuration, or your ISP's DNS servers might be down. Restarting your router often helps. Also check if your firewall is blocking outbound DNS (UDP port 53). On Linux, you can inspect with sudo iptables -L (if iptables is in use). On Windows, check the Windows Firewall rules. If you are on a corporate network, the IT department might restrict DNS queries to specific servers.
Frequently Asked Questions
Why does wget say "could not resolve host" but my browser works?
Your browser might be using a different DNS configuration, such as a system proxy or a built-in DNS-over-HTTPS. wget uses the system's DNS settings directly. Check if your browser has a proxy enabled or uses secure DNS — those settings do not affect wget. Also, your browser might have cached the IP address, while wget does a fresh lookup.
Can I use a different DNS server just for wget?
Yes. You can temporarily edit /etc/resolv.conf (on Linux) to add nameserver 8.8.8.8 at the top, but this file may be overwritten by network managers. A more permanent solution is to change the DNS settings in your router or network manager. There is no wget-specific option to set a DNS server; wget relies on the system.
What is the difference between "could not resolve host" and "connection refused"?
"Could not resolve host" means the DNS lookup failed — the domain name could not be translated to an IP. "Connection refused" means the DNS lookup succeeded, but the server at that IP is not accepting connections on the port you requested. The latter usually means the server is down or a firewall is blocking the port.
Does using an IP address instead of a hostname always work?
Not always. Many websites use virtual hosting, meaning multiple domains share the same IP address. The server needs the Host header to know which site to serve. If you use wget with just an IP, you may get a default page or an error. You can set the Host header manually with --header="Host: example.com".
How do I flush DNS cache on my system?
On Linux with systemd-resolved, use sudo resolvectl flush-caches. On older systems, sudo /etc/init.d/nscd restart if nscd is installed. On macOS, sudo dscacheutil -flushcache. On Windows, open Command Prompt as administrator and run ipconfig /flushdns.
Can a VPN cause this error?
Yes. A VPN changes your network interface and may route DNS queries through its own servers. If the VPN's DNS is misconfigured or the VPN is not fully connected, you may get resolution failures. Disconnect the VPN and test wget again. If it works, the VPN is the culprit.