To troubleshoot a network issue in Linux, start by checking the physical link and your IP configuration with ip link and ip addr, then test connectivity with ping, and finally trace the path with traceroute and check DNS with dig. This guide walks through each step in order, from the cable to the application, so you can isolate the fault quickly.
Before You Start: Know Your Tools
Linux gives you a powerful set of command-line tools for network diagnostics. Most are part of the iproute2 package (the ip command) and the ping utility. Others like traceroute, dig, and ss may need to be installed via your package manager (e.g., apt install dnsutils traceroute on Debian/Ubuntu, or dnf install bind-utils traceroute on Fedora/RHEL). Knowing which tool answers which question is half the battle: ip shows your own configuration, ping tests reachability, traceroute shows the path, and dig checks name resolution.
Step 1: Check the Physical Layer
Before blaming software, ensure the cable is plugged in and the link is up. Run:
ip link show
Look for your interface (e.g., eth0, enp3s0, wlan0). If the state is DOWN, bring it up with sudo ip link set dev eth0 up. If it says NO-CARRIER, the cable or the switch port is the problem. For Wi-Fi, use nmcli device status to see if the radio is enabled and connected to a network.
Step 2: Verify IP Configuration
Run ip addr show to see if your interface has an IPv4 address. If you see only 127.0.0.1 (loopback) and no address on your interface, you need to obtain one. For DHCP, use sudo dhclient eth0 (or restart NetworkManager with sudo systemctl restart NetworkManager). For a static IP, check your config file (e.g., /etc/network/interfaces or Netplan YAML files in /etc/netplan/). Also verify the default gateway with ip route show – it should list a default route like default via 192.168.1.1 dev eth0. If the gateway is missing, you can add it with sudo ip route add default via 192.168.1.1.
Step 3: Test Local Connectivity
Ping your own IP address first to confirm the stack works: ping 192.168.1.10. Then ping the gateway: ping 192.168.1.1. If that fails, the problem is between you and the router (cable, Wi-Fi, or router config). If it succeeds, move to external IPs: ping 8.8.8.8 (Google DNS). If that works but pinging a domain name like google.com fails, the issue is DNS resolution, not connectivity.
Step 4: Trace the Route
If pinging an external IP fails, use traceroute 8.8.8.8 to see where packets stop. The output lists each hop (router) along the path. A line with * * * may indicate a router that blocks ICMP, but if the final destination answers, that’s fine. If the trace stops at a certain hop and never reaches the destination, that router or the link beyond it is likely the problem. For IPv6, use traceroute6.
Step 5: Check DNS Resolution
Use dig google.com to query DNS. Look at the ANSWER SECTION – if you get an IP address, DNS works. If you get NXDOMAIN or a timeout, check your DNS servers in /etc/resolv.conf (or via NetworkManager). You can test a different DNS server directly: dig @8.8.8.8 google.com. If that works, your configured DNS server is unreachable or misconfigured. For a quick temporary fix, add nameserver 8.8.8.8 to /etc/resolv.conf (though changes may be overwritten).
Step 6: Inspect Open Ports and Services
If you can ping but can’t access a specific service (like a web server), check if the port is listening locally with ss -tulpn. This shows listening TCP/UDP ports and the associated processes. If the port isn’t listed, the service isn’t running. If it’s listening but you can’t connect from another machine, check your firewall with sudo iptables -L or sudo nft list ruleset. On systems with firewalld, use sudo firewall-cmd --list-all. Temporarily stop the firewall to test: sudo systemctl stop firewalld (remember to start it again).
Common Problems and Quick Fixes
- No IP address – DHCP lease failed. Check if the DHCP server is reachable, or set a static IP.
- DNS not resolving – Try
dig @8.8.8.8; if that works, fix your DNS config. - Wi-Fi keeps dropping – Check power management:
sudo iwconfig wlan0 power off(use your interface name). - Interface is DOWN – Bring it up with
ip link set dev eth0 up, or check if NetworkManager is managing it. - Can’t ping external IPs but can ping gateway – Likely a routing issue or ISP problem; check
ip routefor a default route. - Slow throughput – Use
iperf3to test bandwidth between two machines, not just ping.
When to Use Static vs DHCP
For servers, a static IP is often preferred so services have a fixed address. For desktops and laptops, DHCP is simpler. You can mix: use DHCP for the address but set a static DNS server. To set a static IP with ip, use sudo ip addr add 192.168.1.50/24 dev eth0 and add a default route. However, this is temporary – to make it permanent, edit your network configuration files or use NetworkManager’s nmcli.
Safety and Good Practices
When troubleshooting, avoid making changes that could lock you out of a remote machine. If you’re SSH’d in, don’t change the IP or firewall rules without having a backup plan (like a scheduled task to revert). Always document what you change. Use sudo only when needed. For firewall changes, test with a temporary rule first, and consider using firewall-cmd --add-service=http --permanent instead of editing iptables directly. Also, be aware that some networks block ICMP (ping) for security reasons – a lack of ping response doesn’t always mean the host is down.
Frequently Asked Questions
What does “Network is unreachable” mean?
This error usually means you have no route to the destination. Check your default gateway with ip route. If there’s no default route, add one, or check your DHCP configuration.
How do I find my IP address in Linux?
Use ip addr show or the older ifconfig (if installed). Look for the inet line under your active interface – it shows your IPv4 address.
Why can I ping an IP but not a domain name?
That’s a DNS issue. Your system can’t resolve the domain to an IP. Check /etc/resolv.conf and try dig @8.8.8.8 google.com to see if an external DNS works.
How do I restart networking on Linux?
On systemd systems, use sudo systemctl restart NetworkManager (for NetworkManager) or sudo systemctl restart networking (for the classic networking service). On older systems, sudo service networking restart may work.
What is the difference between ping and traceroute?
Ping tests if a host is reachable and measures round-trip time. Traceroute shows the path packets take, listing each router hop, which helps identify where packets are being dropped or delayed.
How do I check if a specific port is open?
Use ss -tulpn | grep :80 to see if a service is listening on port 80 locally. To test from another machine, use nc -zv 192.168.1.10 80 (netcat) or telnet 192.168.1.10 80.
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
- Gmail Gemini Privacy: Data Access & Limit Settings
- Fix Outlook Inbox Corruption with DISM in Windows
- How to Set Up Apple Pay on iPhone
- How to Choose a Refurbished iPhone With Years of Support
- Voice Dictation in Google Docs: How to Use It
- Turn Off Message Notifications on Mac