How to Fix ‘Network Is Unreachable’ Error in Ubuntu

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 DOWN state 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-networkd competing to manage the same physical network interface.
  • Subnet Mask Mismatch: An incorrect CIDR prefix (e.g. /32 instead 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:

  1. Open a terminal and check your active network interfaces:
    ip link show
    Look for your primary interface (e.g. eth0, enp3s0, or wlan0) and verify whether it displays state UP or state DOWN.
  2. Inspect assigned IP addresses:
    ip addr show
    Confirm that an authentic IPv4 address is bound to your interface.
  3. Display the active routing table:
    ip route show
    Look for a line beginning with default via <gateway-ip> dev <interface>. If no line starting with default appears, 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:

  1. If your interface is down, bring it up with:
    sudo ip link set dev enp3s0 up
    (Replace enp3s0 with your actual interface identifier.)
  2. Add your local router as the default gateway:
    sudo ip route add default via 192.168.1.1 dev enp3s0
    (Replace 192.168.1.1 with your router’s actual local IP address.)
  3. Test external reachability immediately:
    ping -c 3 1.1.1.1
    If ping replies are received successfully, the route is restored. Now make the configuration persistent.

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:

  1. List existing Netplan files:
    ls /etc/netplan/
  2. Edit your configuration file (for example, 01-netcfg.yaml or 50-cloud-init.yaml):
    sudo nano /etc/netplan/01-netcfg.yaml
  3. Ensure your static configuration uses modern routing syntax (avoiding deprecated gateway4 directives):
    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
    (Ensure indentation uses exactly two spaces per level; do not use Tab characters.)
  4. Save the file by pressing Ctrl + O, then exit with Ctrl + X.
  5. 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:

  1. For server installations using systemd-networkd:
    sudo systemctl restart systemd-networkd
    sudo systemctl restart systemd-resolved
  2. For Ubuntu Desktop using NetworkManager:
    sudo systemctl restart NetworkManager
  3. 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:

  1. Check the status of Uncomplicated Firewall (UFW):
    sudo ufw status verbose
  2. Ensure default outgoing traffic is set to allow:
    sudo ufw default allow outgoing
  3. If issues persist, test temporarily disabling UFW:
    sudo ufw disable
    Test connection with curl -I https://digitash.com to confirm end-to-end communication.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.