When running commands such as ping, curl, or apt update in Ubuntu terminal sessions, the operating system can fail with an explicit diagnostic message: connect: Network is unreachable. Unlike DNS errors where server names cannot be resolved into IP addresses, this error indicates a low-level kernel networking failure: the Linux networking stack has no valid route configured in its routing table to transmit packets toward the destination network subnet.
Diagnosing and fixing the unreachable network error requires inspecting kernel routing tables, verifying network interface state, and restoring proper default gateway configurations in Netplan or NetworkManager.
Why Does Ubuntu Report ‘Network is unreachable’?
The Linux kernel inspects the local routing table whenever an application requests socket transmission. If the destination IP address does not match any local subnet and no default gateway route (0.0.0.0/0) exists, the kernel drops the packet immediately with the ENETUNREACH error code. Key causes include:
- Missing Default Gateway: The DHCP lease expired or the static network configuration omitted the default gateway parameter.
- Interface Down or Unassigned: The physical Ethernet or Wi-Fi interface is in a
DOWNstate or failed to obtain an IPv4/IPv6 lease. - Netplan YAML Syntax Errors: Indentation errors or depreciated gateway directives (such as
gateway4) prevent Netplan from applying route tables upon boot. - Conflicting Network Daemons: NetworkManager and
systemd-networkdcompeting to manage the same physical network interface. - Subnet Mask Mismatch: An incorrect CIDR prefix (e.g.
/32instead of/24) isolates the host from reaching its local gateway.
Step 1: Inspect Interface State and Routing Tables
Verify whether your physical interface has an active link and check the kernel routing table:
- Open a terminal and check your active network interfaces:
Look for your primary interface (e.g.ip link showeth0,enp3s0, orwlan0) and verify whether it displaysstate UPorstate DOWN. - Inspect assigned IP addresses:
Confirm that an authentic IPv4 address is bound to your interface.ip addr show - Display the active routing table:
Look for a line beginning withip route showdefault via <gateway-ip> dev <interface>. If no line starting withdefaultappears, the system cannot reach any external networks.
Step 2: Bring Up the Interface and Add a Temporary Default Route
To restore immediate network connectivity without rebooting:
- If your interface is down, bring it up with:
(Replacesudo ip link set dev enp3s0 upenp3s0with your actual interface identifier.) - Add your local router as the default gateway:
(Replacesudo ip route add default via 192.168.1.1 dev enp3s0192.168.1.1with your router’s actual local IP address.) - Test external reachability immediately:
If ping replies are received successfully, the route is restored. Now make the configuration persistent.ping -c 3 1.1.1.1
Step 3: Configure Netplan for Persistent Routing
In modern Ubuntu releases (Ubuntu 20.04, 22.04, and 24.04 LTS), network configuration is managed via Netplan YAML files:
- List existing Netplan files:
ls /etc/netplan/ - Edit your configuration file (for example,
01-netcfg.yamlor50-cloud-init.yaml):sudo nano /etc/netplan/01-netcfg.yaml - Ensure your static configuration uses modern routing syntax (avoiding deprecated
gateway4directives):
(Ensure indentation uses exactly two spaces per level; do not use Tab characters.)network: version: 2 renderer: networkd ethernets: enp3s0: dhcp4: no addresses: - 192.168.1.150/24 routes: - to: default via: 192.168.1.1 nameservers: addresses: - 1.1.1.1 - 8.8.8.8 - Save the file by pressing
Ctrl + O, then exit withCtrl + X. - Apply the new network configuration:
sudo netplan generate sudo netplan apply
Step 4: Restart Network Services
If your system relies on systemd-networkd or NetworkManager, restart the respective daemon:
- For server installations using
systemd-networkd:sudo systemctl restart systemd-networkd sudo systemctl restart systemd-resolved - For Ubuntu Desktop using NetworkManager:
sudo systemctl restart NetworkManager - Verify that default routes are actively bound:
ip route show
Step 5: Inspect Local Firewall Rules
Misconfigured local firewall policies can reject outbound packets before they traverse the interface:
- Check the status of Uncomplicated Firewall (UFW):
sudo ufw status verbose - Ensure default outgoing traffic is set to allow:
sudo ufw default allow outgoing - If issues persist, test temporarily disabling UFW:
Test connection withsudo ufw disablecurl -I https://digitash.comto confirm end-to-end communication.