Fix Network Is Unreachable on Linux

Tested on RHEL 10.2 (Coughlan)
Package iproute 6.17.0-2.el10
NetworkManager 1.56.0-1.el10
Applies to Ubuntu, Debian, Kali Linux, Linux Mint, Pop!_OS, Raspberry Pi OS, elementary OS, Zorin OS, Parrot OS, MX Linux, RHEL, Rocky Linux, AlmaLinux, Oracle Linux, CentOS Stream, Fedora, Arch Linux
Privilege Normal user for read-only checks; sudo or root to change routes, interfaces, and NetworkManager profiles
Scope Diagnose and fix network is unreachable when ping, curl, ssh, or package managers cannot reach remote IPs. Covers interface state, ip route and ip route get, default gateway, manual routes, and NetworkManager. Does not cover firewall REJECT cases that masquerade as no route to host.
Related guides Fix SSH no route to host
ip route command
nmcli command examples
Restart network on RHEL family
Test port connectivity

ping 8.8.8.8 answers with connect: Network is unreachable while ping 192.168.56.220 on the same LAN still works. That pattern means the host has link connectivity locally but the kernel cannot pick a path to addresses outside your connected subnets — usually a missing or wrong default route.

Work through interface state, then ip route get, then the gateway and NetworkManager profile that should install it.


What network is unreachable means

Linux returns ENETUNREACH when the routing table has no entry for the destination and no default route covers it. Tools phrase it differently:

Tool Typical message
ping connect: Network is unreachable
curl / wget Failed to connect / Network is unreachable
ssh connect to host …: Network is unreachable
ip route get RTNETLINK answers: Network is unreachable

This is not a DNS failure — use an IP address in your first test so name lookup stays out of the path. If only hostnames fail while IPs work, see temporary failure in name resolution instead.

IMPORTANT
This guide fixes local routing and gateway configuration. A remote firewall that REJECTs traffic can make SSH print no route to host even when your routing table looks fine — that path is covered in Fix SSH no route to host.

Check interface state and IP address

A route cannot work if the outbound interface is down or has no IPv4 address. List link state first:

bash
ip -br link

Sample output:

output
lo               UNKNOWN        00:00:00:00:00:00 <LOOPBACK,UP,LOWER_UP>
enp0s3           UP             08:00:27:2d:cd:83 <BROADCAST,MULTICAST,UP,LOWER_UP>
enp0s8           UP             08:00:27:c4:4f:20 <BROADCAST,MULTICAST,UP,LOWER_UP>

UP in the state column and LOWER_UP in the flags mean the NIC is administratively up and sees carrier. DOWN or missing LOWER_UP on the interface you expect to use needs a link fix before you chase gateways.

Confirm the interface that should reach the internet has an address:

bash
ip -4 addr show enp0s3
output
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic noprefixroute enp0s3
       valid_lft 86395sec preferred_lft 86395sec

An inet line with a mask shows the host is addressed on that subnet. No inet line means DHCP may have failed or the profile is static without an address — reconnect or fix the NetworkManager profile before adding routes.


Check route selection with ip route get

ip route get shows which interface and source IP the kernel would use for a destination. Run it against a remote IP you cannot reach:

bash
ip route get 8.8.8.8

When routing works, you get a via gateway and dev interface:

output
8.8.8.8 via 10.0.2.2 dev enp0s3 src 10.0.2.15 uid 0
    cache

When no route matches, the kernel answers immediately:

bash
ip route get 8.8.8.8
output
RTNETLINK answers: Network is unreachable

That response is the same condition ping reports — there is no path in the table for that destination.

List the full IPv4 table for context:

bash
ip -4 route

Sample output on a host missing the default route:

output
10.0.2.0/24 dev enp0s3 proto kernel scope link src 10.0.2.15 metric 112
192.168.56.0/24 dev enp0s8 proto kernel scope link src 192.168.56.116 metric 113

Only scope link entries for directly connected subnets and no default via … line explains why off-subnet addresses are unreachable. For flag and metric detail, see ip route command.


Check the default gateway

The default route sends traffic to destinations outside your local subnets. Look for it explicitly:

bash
ip -4 route show default

Working output:

output
default via 10.0.2.2 dev enp0s3 proto dhcp src 10.0.2.15 metric 112

No output means every off-subnet destination will hit network is unreachable until you add a default route.

NetworkManager stores the gateway it learned from DHCP on the device view — replace enp0s3 with your uplink interface:

bash
nmcli dev show enp0s3 | grep IP4.GATEWAY
output
IP4.GATEWAY:                            10.0.2.2

A lab-only NIC often has no gateway by design:

bash
nmcli dev show enp0s8 | grep IP4.GATEWAY
output
IP4.GATEWAY:                            --

Traffic to the internet must leave through the profile that has a gateway, not the isolated lab interface.


Fix a missing or incorrect route

Pick a fix that matches how the host is managed. These examples use gateway 10.0.2.2 on enp0s3 — substitute your gateway IP and interface from ip route show default or nmcli dev show.

Temporary default route with ip route

For a quick test or rescue session, add a default route manually:

bash
sudo ip route add default via 10.0.2.2 dev enp0s3

Confirm the kernel now selects a path:

bash
ip route get 8.8.8.8
output
8.8.8.8 via 10.0.2.2 dev enp0s3 src 10.0.2.15 uid 0
    cache

ip route add lasts until reboot or until NetworkManager reapplies the profile. Use it to prove the gateway is correct, then make the change persistent through NetworkManager or your netplan config.

Static default on a single subnet

If the host should reach only one remote network, not the whole internet, add a narrower route instead of a default:

bash
sudo ip route add 203.0.113.0/24 via 10.0.2.2 dev enp0s3

Verify with ip route get against an address inside that prefix. Default routes are still the common fix for general internet access.


Check NetworkManager configuration

On NetworkManager-managed systems, the connection profile owns addresses, gateway, and DNS. See which profile is active:

bash
nmcli device status
output
DEVICE  TYPE      STATE                   CONNECTION
enp0s3  ethernet  connected               enp0s3
enp0s8  ethernet  connected               enp0s8
lo      loopback  connected (externally)  lo

If the default route disappeared after a manual ip route del, reactivating the uplink profile often restores DHCP routes:

bash
sudo nmcli connection up enp0s3

Check the routing table again:

bash
ip -4 route show default
output
default via 10.0.2.2 dev enp0s3 proto dhcp src 10.0.2.15 metric 114

For a static uplink, set the gateway on the profile so it survives reboot — adjust addresses to match your network:

bash
sudo nmcli connection modify enp0s3 ipv4.method manual ipv4.addresses '10.0.2.15/24' ipv4.gateway '10.0.2.2' ipv4.dns '8.8.8.8'

Apply the profile:

bash
sudo nmcli connection up enp0s3

ipv4.gateway must point at a router on a connected subnet. A gateway outside the interface subnet leaves you with the same unreachable errors.

On Debian and Ubuntu with Netplan or systemd-networkd, the same logic applies — gateway belongs in the LAN profile. After edits, use refresh network on Ubuntu steps to apply without a full reboot.


Verify connectivity

Re-run the same checks that failed before.

Routing decision:

bash
ip route get 8.8.8.8
output
8.8.8.8 via 10.0.2.2 dev enp0s3 src 10.0.2.15 uid 0
    cache

ICMP to a public resolver:

bash
ping -c2 -W3 8.8.8.8
output
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=117 time=19.4 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=117 time=18.7 ms

--- 8.8.8.8 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms

Some networks block ICMP. If ip route get looks correct but ping shows loss, test TCP with test port connectivity or curl -sI --max-time 5 https://1.1.1.1.

Confirm local LAN traffic still works on interfaces without a default route:

bash
ping -c1 -W2 192.168.56.220
output
PING 192.168.56.220 (192.168.56.220) 56(84) bytes of data.
64 bytes from 192.168.56.220: icmp_seq=1 ttl=64 time=1.21 ms

Replies here with a restored default route confirm both the lab path and the internet path.


Network is unreachable vs no route to host

Both errors sound like routing problems but point at different layers:

Message errno Typical cause ip route get
Network is unreachable ENETUNREACH No route or default gateway for that destination Fails with RTNETLINK answers: Network is unreachable
No route to host EHOSTUNREACH Route exists; ICMP unreachable from gateway, ARP failure, or firewall REJECT Usually prints via and dev

ping to an unused address on the same subnet often ends in 100% packet loss after ARP times out — not the same as network is unreachable, which appears before any packet leaves for off-subnet destinations.

SSH and other TCP clients can print no route to host when a firewall REJECTs the connection even though ip route get looks healthy. Walk through Fix SSH no route to host when routing checks pass but one service still fails.


Troubleshooting

Symptom Likely cause Fix
ip route get prints Network is unreachable No default route and no specific route to destination Add default via <gw> dev <iface> or fix NetworkManager ipv4.gateway
LAN ping works; internet IP fails Default route missing or points at wrong interface ip -4 route show default; restore gateway on uplink profile, not lab-only NIC
Interface DOWN or no inet address Link down, cable, or DHCP failure ip link set dev up; fix L1/L2; nmcli connection up
Route added but lost after reboot Manual ip route only Set ipv4.gateway on NM profile or Netplan equivalent
ip route get OK; SSH still unreachable Firewall REJECT or service not listening Not ENETUNREACH — see SSH no route to host guide
IPv6-only error on dual-stack host No IPv6 default route ip -6 route; configure ipv6.gateway on connection profile
Works until VPN connects VPN replaced default route with broken tunnel Check VPN split-tunnel settings; restore corporate gateway routes

References


Summary

Network is unreachable means the kernel routing table has no usable path to the destination. The quickest signal is ip route get on a remote IP — when it answers RTNETLINK answers: Network is unreachable, you are looking at a missing default route or a missing static route, not DNS or a down web server.

Start with interface state and addresses, read ip -4 route for a default via line, and confirm the gateway lives on the uplink profile that actually reaches your router. A manual ip route add default proves the gateway; nmcli connection modify with ipv4.gateway keeps it across reboots on NetworkManager hosts.

Local subnet pings can still succeed while every internet IP fails — that split is normal when only the default route is wrong. If routing checks pass but SSH prints no route to host instead, shift to firewall and neighbor troubleshooting rather than adding more routes.

For day-to-day route inspection and persistent static routes, keep ip route command and nmcli command examples nearby.


Frequently Asked Questions

1. What does network is unreachable mean on Linux?

The kernel has no matching route for the destination address. ping and curl surface this as connect Network is unreachable or RTNETLINK answers Network is unreachable from ip route get. It is a routing-table problem, not DNS or a remote service refusing the connection.

2. How is network is unreachable different from no route to host?

Network is unreachable means no route exists locally for that destination network. No route to host usually means a route was found but an intermediate device or firewall returned ICMP host unreachable, or neighbor resolution failed on the same subnet. See the comparison section and the SSH-focused guide for EHOSTUNREACH cases.

3. Can I ping local IPs when the default route is missing?

Yes. Connected subnets still have kernel link routes. ping to an address on your own LAN can succeed while ping to the internet prints network is unreachable because no default gateway route exists.

4. Why does ip route get show Network is unreachable?

ip route get asks the kernel which path it would use. When no route matches the destination and no default route covers it, the kernel returns RTNETLINK answers Network is unreachable instead of printing via and dev lines.

5. Will fixing DNS solve network is unreachable?

No. DNS failures happen after routing works. If ping to 8.8.8.8 already prints network is unreachable, fix routes and the gateway before touching resolv.conf or nameservers.
Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with more than 15 years of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive experience, he excels across development, DevOps, networking, and security, delivering robust and efficient solutions for diverse projects.

  • Go (programming language)
  • Python (programming language)
  • DevOps
  • Computer Security
  • Cloud Computing
  • Kubernetes
  • Linux
  • Ansible (software)