If your Linux machine loses connectivity, the quickest fix is usually to restart the network service with sudo systemctl restart NetworkManager (or networking on some distros), then check with ip a and ping. Below are the exact commands for diagnosing and resolving common network problems, from a dead interface to a wrong DNS setting.
Start With the Basics: Check Link and IP
Before changing anything, see what the kernel thinks about your network. Run ip a (or the older ifconfig) to list all interfaces. Look for state UP and an IPv4 address like 192.168.1.10/24. If the interface shows state DOWN, bring it up with:
sudo ip link set eth0 up
Replace eth0 with your actual interface name (often enp3s0 or wlan0). If you use DHCP, request a new lease with sudo dhclient -r eth0 && sudo dhclient eth0 (or sudo dhcpcd on Arch). Then verify you have a route to the gateway:
ip route show
The default route should point to your router, e.g. default via 192.168.1.1 dev eth0. If that line is missing, add it manually with sudo ip route add default via 192.168.1.1, but first make sure the gateway IP is correct for your LAN.
Restart the Network Service
When the interface is up but you still have no internet, the network manager may be stuck. On systemd-based distros (most modern ones), restart the service that manages your connections:
- NetworkManager (default on Ubuntu, Fedora, Debian desktop):
sudo systemctl restart NetworkManager - systemd-networkd (often on servers or minimal installs):
sudo systemctl restart systemd-networkd - networking (older Debian/Ubuntu servers using /etc/network/interfaces):
sudo systemctl restart networking
After restarting, check the service status with systemctl status NetworkManager to see if it reports errors. If the service fails to start, look at the logs with journalctl -u NetworkManager -n 50 to see why.
Ping and Traceroute: Find Where It Breaks
Ping is your best friend for isolating the problem. Test in this order:
ping 127.0.0.1– verifies your TCP/IP stack is working.ping 192.168.1.1– your gateway; if this fails, the issue is local (cable, Wi-Fi, router).ping 8.8.8.8– a public IP; if this works but the next fails, it’s DNS.ping google.com– if this fails but 8.8.8.8 worked, your DNS is broken.
If pings to the gateway fail, check the physical layer: is the cable plugged in? Is Wi-Fi connected? Use iwconfig or nmcli dev wifi list to see available networks. For a more detailed path, install and run traceroute 8.8.8.8 to see where packets stop.
Fix DNS Issues
DNS problems are extremely common. If ping 8.8.8.8 works but ping google.com doesn’t, your resolver is misconfigured. Check the current DNS servers with cat /etc/resolv.conf. If it’s empty or points to a dead server, edit it (or better, edit your network manager’s config). For a quick test, temporarily set Google’s DNS:
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf
That works immediately, but it will be overwritten on reboot or when NetworkManager renews. To make it permanent, either edit /etc/systemd/resolved.conf (set DNS=8.8.8.8) or use nmcli:
nmcli con mod "YourConnectionName" ipv4.dns "8.8.8.8 1.1.1.1" nmcli con up "YourConnectionName"
Find your connection name with nmcli con show. If you use a static configuration, also check that you set a valid DNS server in your network config file.
Renew DHCP Lease and Flush ARP
Sometimes the router gives you a stale IP or the ARP cache (which maps IPs to MAC addresses) is corrupted. Release and renew the lease:
sudo dhclient -r eth0 sudo dhclient eth0
If you use NetworkManager, you can also do sudo nmcli con down "name" && sudo nmcli con up "name". Flush the ARP table to clear any bad entries:
sudo ip neigh flush all
Then check ip a again to see if you got a new IP. If you keep getting the same IP and it doesn’t work, try rebooting your router (unplug for 30 seconds) before blaming Linux.
Common Problems and Their Quick Fixes
- No Wi-Fi interface at all:
rfkill list– if it shows “Soft blocked: yes”, runsudo rfkill unblock wifi. Also checkip linkfor awlan0interface. - Interface has no IP: Try
sudo dhclient eth0or check if your router has DHCP disabled. - Can ping IP but not hostname: DNS issue – see the section above.
- NetworkManager is running but no connection:
nmcli device status– if the device is “disconnected”, runnmcli device connect eth0. - Firewall blocking everything: If you recently enabled a firewall, test with
sudo ufw disable(Ubuntu) orsudo systemctl stop firewalld(Fedora). Re-enable after testing.
If none of these work, check the kernel log for driver errors: dmesg | grep -i eth or dmesg | grep -i wlan. A missing driver is a different problem that usually requires installing firmware packages.
Frequently Asked Questions
Why does my network work after reboot but not after suspend?
This is a common power-management bug. The Wi-Fi or Ethernet card fails to wake up properly. Try sudo systemctl restart NetworkManager after resume, or disable power saving on the device with sudo ethtool -s eth0 wol d (for Ethernet) or iwconfig wlan0 power off (for Wi-Fi).
What does “Temporary failure in name resolution” mean?
It means your system cannot reach a DNS server. Check /etc/resolv.conf and verify you can ping a public IP like 8.8.8.8. If you can, then fix DNS as described above. If you can’t ping any IP, the problem is upstream (router or ISP).
How do I find my network interface name?
Run ip link or ls /sys/class/net. Common names are eth0, enp3s0, wlan0, or wlp2s0. The lo interface is the loopback – ignore it.
Is it safe to restart NetworkManager while connected via SSH?
Yes, but you will lose the connection for a few seconds. If the restart fails, you may be locked out. To be safe, schedule the restart with sudo shutdown -r +1 (reboots in 1 minute) or use a screen/tmux session so you can recover if the connection drops.
Why does my static IP stop working after a while?
Usually it’s an IP conflict with another device on your LAN. Check with arp -a to see if the gateway MAC changed. Also verify your netmask and gateway are correct – a wrong netmask will make you unreachable. Use ip addr show to confirm the settings you set are actually applied.
Can I use these commands on any Linux distribution?
Yes, the ip, ping, and dhclient commands work on all distros. The service names differ: NetworkManager on most desktops, networking on Debian/Ubuntu servers, systemd-networkd on minimal installs. If you use a non-systemd distro (like Alpine), replace systemctl with rc-service networking restart.
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
- Show User Library in macOS High Sierra & Sierra
- Device Manager Shortcut: Windows 10 Desktop
- How to Remove Forgotten Passcode from iPhone
- Fix Slow Wi-Fi Problem iPhone X: 9 Steps
- How to Check if a Candidate Accepts Crypto Donations
- How to Listen to Deleted Voicemails on iPhone