Cannot resolve hostname in Linux terminal? Start here

Linux & Unix Beginner 👁 6 views 📅 Jun 28, 2026

Your terminal can't resolve hostnames. 99% of the time it's a DNS config issue. Here's how to fix it fast.

1. DNS server address is wrong or missing

This is the big one. I've seen this on fresh Ubuntu 22.04 installs, CentOS 7 boxes, even RHEL 9 servers. The DNS resolver isn't set, or it's pointing to something dead.

First check what DNS you're using right now:

cat /etc/resolv.conf

If you see a line like nameserver 127.0.0.53, that's systemd-resolved running. That's normal on Ubuntu 22.04. But if it says 127.0.0.1 and you don't run a local DNS server, that's your problem.

Fix it temporarily to test:

echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf

If ping google.com works now, you nailed it. Make it permanent by editing your network config file. On Ubuntu with Netplan:

sudo nano /etc/netplan/00-installer-config.yaml

Add or change the nameservers section:

nameservers:
  addresses:
    - 8.8.8.8
    - 1.1.1.1

Then apply:

sudo netplan apply

On older systems with /etc/network/interfaces, you add a line like dns-nameservers 8.8.8.8 1.1.1.1 under your interface.

2. systemd-resolved is interfering

If your /etc/resolv.conf looks like a symlink to /run/systemd/resolve/stub-resolv.conf, systemd-resolved is in charge. It's supposed to be smart, but I've seen it get confused — especially after a network change or VPN disconnect.

Check what it thinks:

resolvectl status

Look for the DNS Servers line. If it's empty or shows something weird like 127.0.0.1:53, you need to fix it.

The blunt fix is to disable systemd-resolved and use a plain /etc/resolv.conf:

sudo systemctl stop systemd-resolved
sudo systemctl disable systemd-resolved
sudo rm /etc/resolv.conf
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf

That'll get you running. But if you want to keep systemd-resolved, configure it properly:

sudo nano /etc/systemd/resolved.conf

Uncomment and set DNS=8.8.8.8 and FallbackDNS=1.1.1.1. Then restart:

sudo systemctl restart systemd-resolved

Don't bother with resolvconf package. It's old and rarely needed now. systemd-resolved handles everything if you set it right.

3. Network interface DNS settings are wrong in NetworkManager

You might have DNS set correctly in /etc/resolv.conf, but NetworkManager overrides it on reboot. This is common on Fedora and RHEL.

Check your connection:

nmcli dev show | grep DNS

If it shows wrong servers, fix it per interface. List your active connections first:

nmcli con show

Then set DNS for the connection (replace "Wired connection 1" with yours):

nmcli con mod "Wired connection 1" ipv4.dns "8.8.8.8 1.1.1.1"
nmcli con mod "Wired connection 1" ipv4.ignore-auto-dns yes

Bring it down and up:

nmcli con down "Wired connection 1" && nmcli con up "Wired connection 1"

Now check again:

cat /etc/resolv.conf

It should show your new DNS servers. If not, you might have a race condition with systemd-resolved. In that case, disable systemd-resolved (fix #2) or set dns=default in /etc/NetworkManager/NetworkManager.conf and restart.

Quick-reference summary table

Cause Check command Quick fix
Wrong DNS in resolv.conf cat /etc/resolv.conf Edit file or use netplan
systemd-resolved broken resolvectl status Disable it, set static DNS
NetworkManager override nmcli dev show | grep DNS Set DNS with nmcli

Try these in order. Fix #1 works for 70% of cases. Fix #2 covers another 20%. Fix #3 is the last 10%. Don't waste time restarting network services or reinstalling packages — it's almost always a DNS config issue.

Was this solution helpful?