sodcalculator

10 Tech How-To

Linux Network Troubleshooting in 20 Minutes

Guide 10-45175 · Updated · Step by step

If your Linux machine has lost network connectivity, you can diagnose and fix most issues within 20 minutes by following a systematic command-line workflow. Start by checking the physical link and IP configuration, then test routing, DNS, and firewall rules in that order.

Why This Workflow Works

Network problems on Linux almost always fall into one of five layers: the physical link, the IP address, the default route, DNS resolution, or firewall rules. By testing each layer in sequence, you avoid the common trap of changing firewall rules when the real issue is a missing default gateway. The commands below are available on virtually every distribution—Debian, Ubuntu, Fedora, Arch, and their derivatives—so you can apply the same steps regardless of your desktop or server environment.

Most issues are misconfigurations, not hardware failures. A cable that has come loose, a DHCP lease that expired, a DNS server that stopped responding, or a firewall rule added during a recent update can all produce the same symptom: “no internet.” The workflow isolates which layer is broken before you change anything.

Step 1: Check the Physical Link

  1. Run ip link to list all network interfaces. Look for the state UP and the flag LOWER_UP on your Ethernet (e.g., eth0, enp3s0) or Wi-Fi interface (e.g., wlan0).
  2. If the interface is DOWN, bring it up with sudo ip link set dev <interface> up.
  3. For Wi-Fi, verify you are connected to the correct SSID with nmcli device status or iw dev <interface> link.
  4. If the link is up but you still have no connectivity, check the cable or Wi-Fi signal strength. A blinking link LED on the NIC is a good sign, but not definitive.

A common mistake is assuming the interface name is eth0. Modern systemd-based distributions use predictable names like enp3s0 or wlp2s0. Always confirm with ip link before proceeding.

Step 2: Verify IP Configuration

Run ip addr show (or ip a) to see whether your interface has an IPv4 address. A valid address looks like 192.168.1.100/24 or 10.0.0.5/24. If you see 169.254.x.x, that is a link-local address—it means DHCP failed. If you see no address at all, you have no IP.

To request a new lease from the DHCP server, run sudo dhclient <interface> (on Debian/Ubuntu) or sudo dhcpcd <interface> (on Arch). If you use NetworkManager, sudo nmcli device reapply <interface> or sudo nmcli connection up <connection-name> will often renew the lease. For a static configuration, check the file in /etc/network/interfaces or the Netplan YAML in /etc/netplan/ (Ubuntu 18.04+).

Verify that the IP is in the same subnet as your router. If your router is at 192.168.1.1 and your machine has 192.168.2.10, you will not be able to reach the gateway. This mismatch is a frequent cause of “no internet but Wi-Fi shows connected.”

Step 3: Test the Default Route

The default route tells your system where to send packets destined for outside your local subnet. Check it with ip route show. You should see a line starting with default via followed by your router’s IP. If that line is missing, no traffic can leave your LAN.

To add a default route, run sudo ip route add default via <router-ip> dev <interface>. For example, sudo ip route add default via 192.168.1.1 dev eth0. This change is temporary; it will disappear after a reboot unless you edit your network configuration file.

Test the route with ping -c 4 8.8.8.8 (Google’s public DNS). If this succeeds, your IP and routing are correct, and the problem is elsewhere. If it fails, check whether your router is actually reachable by pinging its IP: ping -c 4 192.168.1.1. If the router does not respond, the issue is between you and the router—cable, Wi-Fi, or the router itself.

Step 4: Check DNS Resolution

If you can ping an IP address but not a domain name like example.com, DNS is the culprit. Run cat /etc/resolv.conf to see which nameservers are configured. A typical entry is nameserver 8.8.8.8 or your router’s IP. If the file is empty or points to an unreachable server, DNS will fail.

Test DNS with nslookup example.com or dig example.com. If you get a response, DNS works. If not, try switching to a public DNS server temporarily: sudo sh -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf'. On systems using systemd-resolved, edit /etc/systemd/resolved.conf instead, or use resolvectl dns set <interface> 8.8.8.8.

Be aware that /etc/resolv.conf is often a symlink managed by NetworkManager or systemd-resolved. Editing it directly may be overwritten. Use the appropriate tool for your distribution to make permanent changes.

Step 5: Inspect Firewall Rules

If IP, routing, and DNS all work, the problem may be a firewall blocking outgoing or incoming traffic. The default firewall on most Linux distributions is nftables (replacing iptables) or ufw on Ubuntu. Check the current rules with sudo nft list ruleset or sudo iptables -L -n (if iptables is installed).

Look for a policy of DROP on the INPUT or OUTPUT chains. If you recently added a rule that blocks a port, remove it. For example, to allow HTTP traffic temporarily: sudo iptables -I INPUT -p tcp --dport 80 -j ACCEPT. If you use ufw, sudo ufw status shows the active rules, and sudo ufw allow 80/tcp opens the port.

A common misconception is that a firewall only blocks incoming connections. On Linux, the OUTPUT chain can also block outgoing traffic. If you cannot reach any external IP, check both chains. Also verify that the firewall service is actually running: systemctl status firewalld (Fedora/RHEL) or systemctl status ufw (Ubuntu).

Common Pitfalls and Misconceptions

  • “I don’t need to check the cable because Wi-Fi is on.” Wi-Fi can be connected to the router but still have no internet if the router’s uplink is down. Always test the gateway first.
  • “I’ll just restart the network service.” Restarting systemd-networkd or NetworkManager can fix a stuck DHCP lease, but it will not fix a wrong static IP or a missing route. Diagnose before restarting.
  • “IP addresses are permanent.” DHCP leases expire. If your lease ran out and the DHCP server is unreachable, you lose your address. Check the lease time in /var/lib/dhcp/dhclient.leases.
  • “Ping to 8.8.8.8 proves internet works.” It proves IP routing works, but not DNS. Many networks block ICMP echo, so a failed ping does not always mean no connectivity.
  • “IPv6 is irrelevant.” If your network uses IPv6 and your system has no IPv6 address, certain sites may fail to load. Check with ip -6 addr and ping6 if needed.

When to Use Each Tool

Here is a quick reference for which command to use at each stage:

  • ip link — physical link state
  • ip addr — IP address and subnet
  • ip route — routing table and default gateway
  • ping — reachability of a host (ICMP)
  • dig or nslookup — DNS resolution
  • nft or iptables — firewall rules

These tools are installed by default on most distributions. If dig is missing, install dnsutils (Debian/Ubuntu) or bind-tools (Arch). For nft, install nftables if it is not present.

Frequently Asked Questions

Why does my Wi-Fi show connected but I have no internet?

This usually means you are associated with the access point but have not received a valid IP address or default route. Check ip addr for a 169.254.x.x address (DHCP failure) or ip route for a missing default gateway. Reconnect to the network or renew the DHCP lease.

How do I restart networking without rebooting?

Use sudo systemctl restart NetworkManager (if you use NetworkManager) or sudo systemctl restart systemd-networkd (if you use systemd-networkd). On older systems, sudo service networking restart works on Debian/Ubuntu. This is faster than rebooting and often clears a stuck state.

What does “RTNETLINK answers: File exists” mean when adding a route?

It means the route you are trying to add already exists. Check the routing table with ip route show and delete the existing route first with sudo ip route del default via <old-gateway> before adding the new one.

Can I fix DNS by editing /etc/resolv.conf directly?

Yes, but the change may be overwritten by NetworkManager or systemd-resolved. For a permanent fix, edit the configuration file for your network manager. On Ubuntu, use Netplan (/etc/netplan/*.yaml) and run sudo netplan apply. On Fedora, use nmcli or edit /etc/NetworkManager/NetworkManager.conf.

Why does ping to a domain name fail but ping to an IP works?

That is a DNS problem. Your system cannot resolve the domain to an IP. Check /etc/resolv.conf for a valid nameserver, and test with dig example.com. If the nameserver is unreachable, switch to a public one like 8.8.8.8.

Is it safe to disable the firewall to test connectivity?

Yes, temporarily, on a trusted network. Run sudo systemctl stop firewalld (or sudo ufw disable) and test. Re-enable it immediately after the test. Do not leave it disabled on a public network, as it exposes all open ports.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →