Skip to content

How to Fix 'Network is unreachable' Error on Linux

DodaTech 2 min read

In this tutorial, you'll learn about How to Fix 'Network is unreachable' Error on Linux. We cover key concepts, practical examples, and best practices.

The Problem

You run ping google.com or curl https://example.com and get Network is unreachable or connect: Network is unreachable. The system cannot reach the destination because of a misconfigured network interface, missing default gateway, disconnected cable, or a downed network service.

Quick Fix

1. Check if the network interface is up

ip link show

Expected output:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 ...
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 ...

NO-CARRIER means the cable is disconnected or the Wi-Fi is not associated.

2. Check IP address assignment

ip addr show eth0

If no IP is shown, request one via DHCP:

sudo dhclient eth0

3. Check the routing table

ip route show

Expected output:

default via 192.168.1.1 dev eth0
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.100

If there's no default route, add one:

sudo ip route add default via 192.168.1.1 dev eth0

4. Check DNS resolution

cat /etc/resolv.conf

Should contain a valid nameserver. If empty, add Google DNS:

echo 'nameserver 8.8.8.8' | sudo tee /etc/resolv.conf
echo 'nameserver 1.1.1.1' | sudo tee -a /etc/resolv.conf

5. Restart networking service

# systemd-based
sudo systemctl restart networking
# or
sudo systemctl restart NetworkManager

# Check status
sudo systemctl status networking

6. Test connectivity step by step

# Test local network
ping -c 3 192.168.1.1

# Test external IP (bypasses DNS)
ping -c 3 8.8.8.8

# Test DNS resolution
nslookup google.com

# Test full connectivity
ping -c 3 google.com

7. Check if NetworkManager is managing the interface

sudo systemctl status NetworkManager
sudo nmcli device status

Common Causes

Cause Symptom Fix
Cable unplugged Interface shows NO-CARRIER Check physical connection
DHCP not configured No IP address assigned sudo dhclient eth0
Missing default gateway Can ping local IPs, not the internet sudo ip route add default via 192.168.1.1
DNS not configured Can ping IPs but not domain names Add nameserver 8.8.8.8 to resolv.conf
NetworkManager issue Interface managed by unknown service Check systemctl status NetworkManager
Firewall blocking outbound All pings fail Check iptables -L for DROP rules

Prevention

  • Configure static IP or DHCP properly in /etc/network/interfaces or Netplan
  • Set a default route in your network configuration, not manually via ip route
  • Use ping -c 1 8.8.8.8 as a simple connectivity check in monitoring scripts

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro