Skip to content
$ lynuxpro
← Linux

LESSON 18 OF 26 · ADVANCED · 19 MIN

Network troubleshooting playbook

In one minute

  • A fixed, step-by-step order for finding any network problem, plus tcpdump to look at the real packets when simple tools are not enough.
  • Under pressure, people guess and restart things at random. Senior engineers are not faster because they know secret commands. They are faster because they check things in the same order every time.
  • Start at the bottom (does the machine have an address?) and move up one step at a time (route → name → host → port → app). Stop at the first step that fails. That is where the problem is.
  • 👉 Every "can't connect", "it's slow" or "it works sometimes" problem.

Think of it like: a plumber checking for a leak. Start at the water main, then follow the pipe room by room. Do not rip out the kitchen tap before you know the water is even reaching the house.

The method: bottom up, one step at a time

Eight questions, asked in order. Stop at the first "no".

StepQuestionCommand
1Is the network card up, with the right IP?ip -br addr
2Is there a route to where I am going?ip route get DEST
3Does the name turn into the right IP?dig +short name, getent hosts name
4Can I reach the machine?ping -c 3, traceroute
5Is the port open from here?nc -zv host port
6Is the service listening on the server?ss -tulpn (on the server)
7Does the app answer correctly?curl -v
8Is anything blocking in between?Firewalls, security groups, NACLs, NetworkPolicy

Test from both ends when you can: from the client towards the server, and on the server itself with curl localhost.

Remember it: Card → Road → Name → Reach → Port → Listening → App → Blockers.

What the error message tells you

Each error points to a different layer. Read it carefully. It is your biggest clue.

What you seeLayerMost likely causes
Could not resolve hostDNSTypo, wrong resolver, missing private DNS record
Network is unreachableRoutingNo route, missing default gateway
No route to hostRouting or firewallA REJECT rule, or the host is down
TimeoutSomething blockingSecurity group, NACL, server firewall DROP, wrong route
Connection refusedThe serviceNot running, wrong port, listening on 127.0.0.1
Connection reset by peerService or proxyApp crashed mid-request, idle timeout, wrong protocol
TLS errorTLSExpired certificate, wrong name, missing chain
HTTP 502 / 503 / 504Behind the proxyThe app behind it is down, unhealthy or slow
Works sometimesSeveral serversOne bad server, DNS rotation, MTU, connection-table limits

Worked example: "the API cannot reach Redis"

ip -br addrip routedig +short example.comnc -zv 10.0.2.10 5432ss -tulpncurl -v http://localhost/health
SHELLbashutf-8 · 6L
  1. Card and route: the app server is on 10.20.48.15/20 with a default route. Fine.
  2. DNS: getent hosts redis.internal returns 10.20.64.40. Correct.
  3. Port test: nc -zv 10.20.64.40 6379 times out. Something is blocking.
  4. On the Redis server: ss -tulpn shows 127.0.0.1:6379. So even after the firewall is fixed, Redis would refuse other machines.
  5. Two fixes: set Redis to listen on its private IP, and allow the app's subnet in the Redis security group on port 6379.
  6. Check again with nc -zv, then from the app.

Notice there were two problems stacked on top of each other. Keep going until the full end-to-end test passes.

Looking at real packets: tcpdump

tcpdump shows the actual packets going in and out of a network card.

It settles arguments. It shows exactly what is happening, not what tools guess.

👉 When simple tools disagree, or a problem only happens sometimes.

sudo tcpdump -i eth0 port 443
SHELLbashutf-8 · 1L
sudo tcpdump -i any -nn port 5432                 # all traffic on 5432sudo tcpdump -i eth0 -nn host 10.20.64.40         # traffic to or from one hostsudo tcpdump -i eth0 -nn 'tcp[tcpflags] & tcp-syn != 0'   # connection attempts onlysudo tcpdump -i eth0 -w /tmp/cap.pcap port 443    # save for Wireshark
OUTPUTterminalutf-8 · 4L
OptionMeaning
-i eth0 / -i anyWhich network card to listen on
-nnShow numbers, not names (faster and clearer)
-c 50Stop after 50 packets
-w fileSave to a file (open it later in Wireshark)
-APrint the content as text (plain HTTP only)

Reading a TCP handshake

Every TCP connection starts with a 3-step "handshake".

10.20.48.15.51234 > 10.20.64.40.6379: Flags [S]       # client sends SYN10.20.64.40.6379 > 10.20.48.15.51234: Flags [S.]      # server replies SYN-ACK10.20.48.15.51234 > 10.20.64.40.6379: Flags [.]       # client ACK: connected
OUTPUTterminalutf-8 · 3L

Think of it like: "Hello?" (SYN) → "Hello, I hear you" (SYN-ACK) → "Great, let's talk" (ACK).

What you seeMeaning
[S] again and again, no replyPackets are dropped on the way (firewall, security group, route)
[S] then [R.]The server got it but said no: nothing listening, or a REJECT rule
Handshake completes, then [R]The app or proxy closed the connection
[S] reaches the server, but the reply never reaches the clientThe return path is broken: a different route back, or a NACL outbound rule

Capturing on the client and the server at the same time shows exactly where packets disappear.

The strange cases that happen "only sometimes"

ProblemClueCheck
MTU mismatch (packet too big)Small requests work, big ones hang (often over a VPN)ping -M do -s 1472 host; lower the MTU
Connection table fullRandom drops under load; nf_conntrack: table full in dmesgsysctl net.netfilter.nf_conntrack_max
Run out of outgoing portsCannot assign requested address under heavy loadss -s; widen ip_local_port_range; reuse connections
DNS delays in KubernetesSome requests take 5 extra secondsCoreDNS load, the ndots setting
One bad serverEvery Nth request failsTest each server directly with curl --resolve
Different route backSYN arrives, but the reply goes another wayip route get on both sides, check rp_filter

Kubernetes quick checks

kubectl get pods -o wide                      # pod IPs and nodeskubectl get svc,endpoints my-svc             # does the Service have endpoints?kubectl exec -it debug -- nc -zv my-svc 80   # test from inside the clusterkubectl get networkpolicy -A                  # policies that may block traffic
OUTPUTterminalutf-8 · 4L

A Service with no endpoints means no ready pods match its label selector. That is a label typo or a failing readiness check, not a network problem at all.

Real-world scenario: works from one zone, fails from another

Requests from servers in ap-south-1a work. From ap-south-1b they time out.

ip routetraceroute example.com
SHELLbashutf-8 · 2L

The two subnets use different route tables. Subnet b's table is missing the route to the connected (peered) VPC. Comparing ip route get and the AWS route tables for each subnet finds it in minutes.

The lesson: when something works in one place and not another, compare the two setups side by side.

Common mistakes

  • Starting at the top (restarting the app) before checking DNS and connectivity.
  • Testing from the wrong place, such as your laptop on the VPN instead of the real client.
  • Stopping at the first fix when several problems are stacked.
  • Changing several things at once, so you never learn which change worked.

Practice

  1. Write down the eight-step playbook from memory.
  2. A client gets "connection refused" on port 8080. List two possible causes and the command that confirms each.
  3. In a tcpdump, you see repeated SYNs and no replies. What does that tell you?
  4. Requests over the VPN hang only for large file uploads. What would you test?

Cheat sheet

GoalCommand
Route for one addressip route get IP
What apps resolvegetent hosts name
Test a TCP portnc -zv host port
What listens heress -tulpn
Full HTTP and TLS viewcurl -v url
See the packetstcpdump -i any -nn port N
Connection summaryss -s

Key takeaways

  • Check network problems in the same order every time, from the bottom up.
  • Stop at the first step that fails. That is where the problem is.
  • The error message tells you the layer: refused, timeout and reset all mean different things.
  • tcpdump shows the real packets. If the "hello" (SYN) never arrives, it is the network.
  • There can be more than one problem. Keep testing until everything works end to end.