23. Network Troubleshooting
When an application goes offline, blaming the network is the default response. A DevOps engineer must be able to methodically prove exactly where the failure is occurring.
23.1 The Troubleshooting Methodology (Bottom-Up)
Section titled “23.1 The Troubleshooting Methodology (Bottom-Up)”When diagnosing a network issue, never guess. Use the OSI model to work your way from the physical hardware up to the application layer. If you skip a step, you will waste hours debugging a web server when the ethernet cable is simply unplugged.
1. Physical (Is the cable plugged in? Is the VM NIC attached?) ↓ 2. Interface (Is the interface 'UP' in the OS?) ↓ 3. IP (Does the interface have the correct IP address?) ↓ 4. Route (Do we have a Default Gateway to reach the outside?) ↓ 5. DNS (Can we resolve domain names to IPs?) ↓ 6. Port (Is the firewall open? Is the service listening on the port?) ↓ 7. Service (Is the background daemon actually running?) ↓ 8. App (Is the application returning an HTTP 500 error?)23.2 Essential Troubleshooting Tools
Section titled “23.2 Essential Troubleshooting Tools”1 & 2. Physical & Interface (ip)
Section titled “1 & 2. Physical & Interface (ip)”Check if the interface exists and if its state is UP.
ip link show3. IP Configuration (ip)
Section titled “3. IP Configuration (ip)”Verify the machine has the correct IP address.
ip addr show(If you have an IP starting with 169.254.x.x, your DHCP server is unreachable/failing!).
4. Routing & Connectivity (ping, ip, traceroute)
Section titled “4. Routing & Connectivity (ping, ip, traceroute)”First, check if you have a default gateway:
ip route showNext, test if you can reach the gateway, and then test the internet:
# Ping the local gateway firstping 192.168.1.1
# Ping an external IP (bypassing DNS) to prove internet connectivityping 8.8.8.8
# If ping fails, use traceroute to find exactly which router is dropping the packetstraceroute 8.8.8.85. DNS Resolution (dig, nslookup)
Section titled “5. DNS Resolution (dig, nslookup)”If you can ping 8.8.8.8, but you cannot ping google.com, your internet is fine, but your DNS is broken.
nslookup: A simple tool to query a hostname.Terminal window nslookup google.comdig: The advanced tool for DNS troubleshooting. It provides detailed information about MX, TXT, and A records.Terminal window # Query a specific DNS server (e.g., Cloudflare) for a domaindig @1.1.1.1 google.com
6. Ports & Firewalls (ss, nc)
Section titled “6. Ports & Firewalls (ss, nc)”If DNS and routing work, the next step is checking if the port is actually open and listening.
ss: Check if the service is listening locally on the server.Terminal window sudo ss -tulpn | grep 443nc(Netcat): The ultimate tool for testing if a port is reachable from the outside (bypassing the firewall).Terminal window # Check if port 443 is open on a remote servernc -zv webserver.internal.local 443# Output: "Connection to webserver.internal.local 443 port [tcp/https] succeeded!"
7 & 8. Services & Applications (curl, wget, tcpdump)
Section titled “7 & 8. Services & Applications (curl, wget, tcpdump)”If the port is open, you need to check if the application is returning valid data.
curl: Fetches HTTP headers and bodies. Perfect for testing REST APIs.Terminal window # Fetch only the HTTP headers (-I) to check the status code (e.g., 200 OK or 502 Bad Gateway)curl -I https://google.comwget: Designed for downloading files recursively, but useful for testing basic HTTP fetch.tcpdump(The Final Boss): If everything else fails, you must inspect the raw packets on the wire.tcpdumpcaptures network traffic so you can see exactly what is being sent and received.Terminal window # Capture all traffic on port 80 for the eth0 interfacesudo tcpdump -i eth0 port 80