Skip to main content

Linux Network Troubleshooting: A Systematic Approach

Linux Learning Lab
Author
Linux Learning Lab
Writing about code, tools, and workflows.
linux-networking - This article is part of a series.
Part 3: This Article

The Troubleshooting Mindset
#

Network problems feel random, but they’re not. Every issue lives at a specific layer. If you work systematically from the bottom up, you’ll isolate the problem faster than guessing.

The approach:

1. Is the interface up?           (Layer 1/2)
2. Do I have an IP address?       (Layer 3)
3. Can I reach the gateway?       (Layer 3)
4. Can I reach the internet?      (Layer 3)
5. Does DNS resolve?              (Layer 7 — but needed before step 6)
6. Can I reach the destination?   (Layer 4)
7. Does the application respond?  (Layer 7)

Each step eliminates a category of problems. If step 3 works but step 4 doesn’t, the problem is routing — not your local config. DNS is tested before port connectivity because most real-world targets are referenced by hostname.

Step 1: Is the Interface Up?
#

ip link show

Look for state UP on your interface:

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP

If it says state DOWN:

# Bring it up
sudo ip link set eth0 up

# If using NetworkManager
nmcli device connect eth0

Still down? Check physical connections — cable plugged in, Wi-Fi enabled, VM network adapter attached.

# Check if cable is physically connected (Ethernet)
ethtool eth0 | grep "Link detected"

Step 2: Do I Have an IP Address?
#

ip addr show eth0

Look for an inet line:

inet 192.168.1.50/24 brd 192.168.1.255 scope global dynamic eth0

No IP address? DHCP might have failed:

# Request a new lease
sudo dhclient eth0

# Or with NetworkManager
nmcli connection up "Wired connection 1"

# Check DHCP client logs
journalctl -u NetworkManager | grep -i dhcp

Step 3: Can I Reach the Gateway?
#

# Find your gateway
ip route show default
# default via 192.168.1.1 dev eth0

# Ping it
ping -c 4 192.168.1.1

Gateway unreachable?

  • Wrong subnet mask (your IP and gateway aren’t on the same network)
  • Gateway is down
  • ARP resolution failed
# Check ARP table — do you have the gateway's MAC?
ip neigh show | grep 192.168.1.1

# If missing, try arping
arping -c 2 -I eth0 192.168.1.1

Step 4: Can I Reach the Internet?
#

# Ping a public IP (bypasses DNS)
ping -c 4 8.8.8.8

Gateway responds but 8.8.8.8 doesn’t?

  • Firewall blocking outbound traffic
  • ISP issue
  • NAT/routing misconfiguration
# Trace where packets stop
traceroute 8.8.8.8
# or
mtr -r 8.8.8.8

mtr combines ping and traceroute — shows packet loss at each hop:

HOST                   Loss%   Snt   Last   Avg  Best  Wrst
1. 192.168.1.1         0.0%    10    1.2   1.1   0.9   1.5
2. 10.0.0.1            0.0%    10    5.3   5.1   4.8   6.2
3. ???                 100.0%   10    0.0   0.0   0.0   0.0

100% loss at hop 3 means the problem is between hop 2 and 3 — not your machine.

Step 5: Does DNS Resolve?
#

# Test DNS resolution
dig google.com +short

# If dig isn't installed
nslookup google.com

# Or the simplest test
host google.com

DNS not resolving?

# Check what resolver you're using
cat /etc/resolv.conf
# or
resolvectl status

# Test with a known-good resolver directly
dig @8.8.8.8 google.com +short
dig @1.1.1.1 google.com +short
ResultProblem
Works with @8.8.8.8 but not defaultYour configured DNS server is broken
Doesn’t work with any resolverOutbound UDP/53 or TCP/53 is blocked
Partial failures (some domains work)DNS server has stale cache or zone issue

Quick fix — temporarily use a public resolver:

# Test if this fixes the issue
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf

Step 6: Can I Reach the Destination Port?
#

# Test TCP connectivity to a specific port
nc -zv example.com 443

# With a timeout
nc -zv -w 5 example.com 443
ResultMeaning
Connection succeededPort is open, service is reachable
Connection refusedHost is up, but nothing is listening on that port
Connection timed outFirewall is dropping packets, or host is unreachable

Connection refused vs timeout:

  • Refused = the host received your packet and explicitly rejected it (the service isn’t running)
  • Timeout = your packet never got a response (firewall, wrong IP, host down)

This distinction is critical — refused means network is fine, it’s an application problem.

Step 7: Does the Application Respond?
#

# HTTP — check response code and headers
curl -I https://example.com

# Verbose — shows DNS, TCP, TLS, and HTTP details
curl -v https://example.com

# Show timing breakdown
curl -w "\nDNS: %{time_namelookup}s\nConnect: %{time_connect}s\nTLS: %{time_appconnect}s\nFirst byte: %{time_starttransfer}s\nTotal: %{time_total}s\n" -o /dev/null -s https://example.com

The timing breakdown tells you where the slowness is:

PhaseHigh time means
DNSSlow resolver
ConnectNetwork latency or congestion
TLSCertificate issues or slow handshake
First byteServer is slow processing the request

tcpdump: When You Need to See Packets
#

When higher-level tools don’t explain the problem, capture the actual traffic:

Basic captures
#

# All traffic on an interface
sudo tcpdump -i eth0 -n

# Traffic to/from a specific host
sudo tcpdump -i eth0 host 10.0.1.50 -n

# Traffic on a specific port
sudo tcpdump -i eth0 port 443 -n

# Only show SYN packets (new connections)
sudo tcpdump -i eth0 'tcp[tcpflags] & (tcp-syn) != 0' -n

Save to file for Wireshark analysis
#

sudo tcpdump -i eth0 -w /tmp/capture.pcap -c 500

What to look for
#

Symptom in tcpdumpLikely problem
SYN sent, no SYN-ACK backFirewall dropping, host down, wrong route
SYN-ACK received, then RSTPort closed or service crashed
RetransmissionsPacket loss, congestion, MTU issues
Connection established, no dataTLS failure or application-level issue

Common Scenarios
#

“I can’t reach the internet”
#

# Quick diagnosis
ping -c 2 192.168.1.1   # Gateway?
ping -c 2 8.8.8.8       # Internet (no DNS)?
ping -c 2 google.com    # DNS working?
Gateway8.8.8.8google.comProblem
Local config (IP, interface, cable)
Routing or ISP
DNS
It works — problem is elsewhere

“DNS isn’t resolving”
#

# Confirm it's actually DNS
ping -c 2 8.8.8.8        # Works? Then network is fine
dig google.com            # Fails? DNS issue confirmed

# Is the resolver reachable?
ping -c 2 $(grep nameserver /etc/resolv.conf | head -1 | awk '{print $2}')

# Try a different resolver
dig @1.1.1.1 google.com

# Check if port 53 is blocked
nc -zvu 8.8.8.8 53

“Connection refused”
#

# Is the service actually running?
ss -tlnp | grep :80

# If not listening, check the service
systemctl status nginx
journalctl -u nginx --since "5 min ago"

# Is it bound to the right address?
# 127.0.0.1:80 = local only
# 0.0.0.0:80 = all interfaces
ss -tlnp sport = :80

“Connection timeout”
#

# Is there a firewall blocking it?
sudo iptables -L -n | grep -i drop
sudo nft list ruleset | grep drop

# Can you reach the host at all?
ping -c 2 target-host

# Is the port open from a different machine?
# (test from another host to rule out local firewall)

# Trace where it stops
traceroute -p 80 target-host

“It’s slow”
#

# Where is the latency?
curl -w "DNS: %{time_namelookup}s\nTCP: %{time_connect}s\nTLS: %{time_appconnect}s\nFirst byte: %{time_starttransfer}s\nTotal: %{time_total}s\n" -o /dev/null -s https://slow-site.com

# Check for packet loss
mtr -r slow-site.com

# Check for retransmissions
ss -ti dst slow-site.com | grep retrans

# Check MTU issues
ping -c 4 -M do -s 1472 slow-site.com

Quick Reference
#

QuestionCommand
Is the interface up?ip link show
Do I have an IP?ip addr show
What’s my gateway?ip route show default
Can I reach the gateway?ping -c 4 GATEWAY
Can I reach the internet?ping -c 4 8.8.8.8
Does DNS work?dig google.com +short
Is a port open?nc -zv HOST PORT
What’s listening locally?ss -tlnp
Where do packets stop?traceroute HOST or mtr HOST
Show me the packetssudo tcpdump -i eth0 host HOST -n
HTTP timingcurl -w "..." -o /dev/null -s URL
Check firewall rulessudo iptables -L -n

Best Practices
#

  • Always work bottom-up — don’t debug DNS if you can’t ping the gateway
  • Use ping to an IP (like 8.8.8.8) to separate network issues from DNS issues
  • Learn the difference between “refused” and “timeout” — they point to completely different problems
  • Use mtr instead of traceroute — it shows packet loss percentage at each hop
  • Use curl -v for HTTP issues — it shows every step of the connection
  • Capture packets with tcpdump when nothing else explains the problem — the answer is always in the packets
  • When troubleshooting from a remote server, don’t lock yourself out — test firewall changes with a timeout safety net
  • Document what you checked — when escalating to someone else, “I confirmed the gateway responds but packets stop at hop 3” is far more useful than “the network is broken”
linux-networking - This article is part of a series.
Part 3: This Article