4 ways To Fix “Could Not Resolve Host” Error in Linux

Encountering a network error can bring your workflow to a grinding halt. You might be trying to download a tool using the wget command, or perhaps you are attempting to update your system with yum and suddenly hit a wall.

This error indicates that your Linux system cannot translate a domain name (like google.com) into an IP address that the computer understands.

In most cases, this issue stems from misconfigured DNS settings, a disabled network interface, or a lack of internet connectivity.

Key Takeaways: Fixing Host Resolution

  • DNS Nameservers → The primary cause of resolution issues. Ensure your /etc/resolv.conf file contains valid IP addresses for DNS servers.
  • Network Interface Status → Your hardware must be “UP” and connected to the network for DNS queries to reach the internet.
  • Connectivity Test → Always verify if you can reach an external IP (like 8.8.8.8) to determine if the problem is specifically related to DNS or a general network outage.
  • nmcli Tool → The modern standard for managing network settings in distributions like RHEL and Ubuntu.

Method 1: Verify the /etc/resolv.conf File

The /etc/resolv.conf file is the central location where Linux looks for DNS nameservers. If this file is empty or contains incorrect IPs, your system will not be able to resolve any hostnames.

To check the contents of this file, run: cat /etc/resolv.conf

Expected Output:

nameserver 8.8.8.8
nameserver 1.1.1.1

If you do not see a line starting with nameserver, or if the IP address listed is unreachable, you must check your Linux DNS server settings and update them.

Method 2: Check Network Interface Status

Sometimes the “Could Not Resolve Host” error is simply because the network card is turned off or disconnected. You can use the linux ip addr command to see the state of your interfaces.

Run this command for a status overview: nmcli device status

Expected Output:

See also: Mastering the Linux Command Line — Your Complete Free Training Guide

DEVICE  TYPE      STATE      CONNECTION
enp1s0  ethernet  connected  Internal-LAN
lo      loopback  unmanaged  --

If your primary device shows as disconnected or unavailable, your system cannot reach a DNS server. You may need to use nmcli connection up <name> to reactivate it.

Method 3: Test Connectivity via IP Address

To rule out a total internet outage, try pinging a known public IP address rather than a hostname. This bypasses the DNS resolution process entirely.

Run a simple ping test: ping -c 3 8.8.8.8

If the ping is successful but ping google.com fails, the issue is strictly a DNS problem. If both fail, you likely have a broader issue with your default gateway or physical connection.

Method 4: Use the dig Utility for Detailed Diagnosis

The dig (Domain Information Groper) tool allows you to perform manual DNS lookups to see exactly where the failure occurs.

Run this command to test resolution for a specific domain: dig google.com

If the command times out or returns “SERVFAIL,” it confirms that your configured nameservers are not responding to queries.


Step-by-Step Process: Adding a DNS Server via nmcli

If you identify that your DNS settings are missing, follow these steps to add a permanent nameserver using the NetworkManager CLI:

  1. Launch your terminal application.
  2. Identify your connection name by running nmcli connection show.
  3. Set a new DNS server (e.g., Google’s 8.8.8.8) using: sudo nmcli connection modify "Connection Name" ipv4.dns "8.8.8.8".
  4. Set the DNS method to manual if you are not using DHCP: sudo nmcli connection modify "Connection Name" ipv4.method manual.
  5. Restart the connection to apply changes: sudo nmcli connection up "Connection Name".
  6. Verify the fix by running ping google.com.

Summary Table

TaskRecommended CommandPurpose
Check DNS Configcat /etc/resolv.confView current nameservers.
Verify Interfacenmcli device statusCheck if the network is “UP”.
Test Raw Connectionping -c 3 8.8.8.8Test IP-based connectivity.
Manual DNS Lookupdig google.comAudit DNS response data.
Update DNS Settingsnmcli con mod <ID> ipv4.dnsPermanently fix DNS entries.

FAQs

Why does ping work for IP addresses but not hostnames? This indicates a DNS failure. Your system can reach the internet but doesn’t know how to translate names into IPs. Check your /etc/resolv.conf file.

What are the best free DNS servers to use? Commonly used reliable servers include Google DNS (8.8.8.8) and Cloudflare (1.1.1.1). However, be aware that Cloudflare services have occasionally gone down in the past.

Can a firewall cause this error? Yes. If your firewall blocks UDP port 53, your system cannot send or receive DNS queries.


Related Posts

David Cao
David Cao

David is a Cloud & DevOps Enthusiast. He has years of experience as a Linux engineer. He had working experience in AMD, EMC. He likes Linux, Python, bash, and more. He is a technical blogger and a Software Engineer. He enjoys sharing his learning and contributing to open-source.

Articles: 619

Leave a Reply

Your email address will not be published. Required fields are marked *