DEVOPS, SRE AND CLOUD · PART 2 · NETWORKING FOR DEVOPS · DEBUGGING · 43 OF 187

Network Troubleshooting: ss, tcpdump, mtr, curl

A repeatable method for "the service is unreachable", using real outputs from this part: name (dig, getent), route (ip route get, traceroute, mtr), port (ss -tlnp, nc -zv), firewall (timeout vs refused, rule counters), TLS (openssl s_client), the application (curl -w, proxy logs, 502 vs 504), and tcpdump when you need proof, plus how to write the finding up.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
1 / 12

Press play to hear the narration, or step through at your own pace.

Key takeaways

  • Name → route → port → firewall → TLS → app
  • timeout vs refused
  • 502 vs 504
  • tcpdump proves it
  • write it up

Notes

1 The name

Start with the name. getent hosts shows what the application really resolves, including etc hosts. dig shows what DNS says, and dig at the authoritative server shows what was published. Read the status: NXDOMAIN, a missing record; SERVFAIL, a broken resolver; REFUSED, you asked a server that will not answer, as our lab server did. If the address is old, it is caching and TTLs. Write down the IP you got.

Check
$ getent hosts api.internal
  what the app sees
$ dig api.internal +short
$ dig @authoritative ...
NXDOMAIN → missing record
SERVFAIL → resolver broken
REFUSED → wrong server
  (our lab: no upstream)
old IP → TTL, caching

2 The route

Next, the route. ip route get shows which gateway and interface the kernel will use. Network is unreachable, as in our namespace lab, means this host has no route at all. traceroute shows each hop, and mtr runs it continuously with loss per hop, which is how you find where packets die. Loss that starts at one hop and continues to the end is real; loss at a single middle hop is often just a router ignoring traceroute. And check the return path.

Check (our lab)
$ ip route get 10.0.2.20
  via 10.0.1.1 dev va
"Network is unreachable"
  → no route on this host
$ traceroute -n 10.0.2.20
 1 10.0.1.1  2 10.0.2.20
$ mtr -n host  live loss
  per hop
remember the return route

3 The port

Third, the port. On the server, ss minus t l n p shows whether the process is listening, and on which address. ShopRung listened on zero dot zero dot zero dot zero, every interface; a service on one two seven dot zero dot zero dot one can only be reached locally. From the client, netcat minus z v tests the TCP connection. An instant refusal means nothing listens or a reject rule; a hang means packets disappear, which is the next step.

Check
on the server:
$ ss -tlnp | grep 8080
  0.0.0.0:8080 node
  127.0.0.1:8080 → local only
from the client:
$ nc -zv host 8080
refused in ms → no listener
  or a reject rule
timeout → step 4

4 The firewall

Fourth, firewalls. Our drop rule turned a request into a three second timeout, while its counter grew by three SYN packets; a reject rule failed in a tenth of a millisecond. So list the rules with counters and watch which counter grows while you retry. In the cloud, check the security groups on both ends, the network ACLs and route tables, and VPC flow logs, which record rejected connections.

Our measurements
drop rule:   3.002 s timeout
  counter: 3 packets (SYNs)
reject rule: 0.12 ms refused
$ nft list ruleset
$ iptables -L -n -v
  (watch counters grow)
cloud: SG on both ends,
  NACL, route tables,
  VPC flow logs (REJECT)

5 TLS

Fifth, TLS. If TCP connects but HTTPS fails, use openssl s client with the server name. Verify return code zero means the chain is fine. curl's exit sixty covers the two failures we caused: an issuer the client does not trust, and a name not in the certificate. Check the dates for expiry. And remember a strict client, like Python three point thirteen in our lab, may reject what curl accepts.

Check
$ openssl s_client -connect
    host:443 -servername host
Verify return code: 0 (ok)
$ curl -v https://host
exit 60: unknown issuer or
  name mismatch (we saw both)
expired? openssl x509
  -noout -dates
strict clients differ

6 The application

Finally the application. curl minus w splits the request into DNS, connect, TLS and time to first byte, so you know which layer is slow. Read status codes as directions: five oh two means the proxy could not reach the app, and nginx's error log said exactly that, connect failed, connection refused, with the upstream address. Five oh four means the app was too slow. Four two nine and four thirteen are proxy limits, not app bugs.

Check
$ curl -w "dns %{time_
  namelookup} connect ...
  tls %{time_appconnect}
  ttfb %{time_starttransfer}"
502 → proxy could not reach
  upstream (error.log says
  connect() failed 111)
504 → upstream too slow
429/413 → proxy limits

Proof: tcpdump

When teams disagree, capture packets. tcpdump on the client or server, filtered by host and port, shows the truth. A SYN going out with nothing coming back means the packets are dropped on the way. A reset coming back means refused. A full handshake and a request, but no response, puts the problem in the application or proxy. Save a capture with minus w and open it in Wireshark. This ends most network arguments.

Capture
$ tcpdump -ni eth0 host
    10.0.2.20 and port 8080
SYN out, nothing back →
  dropped on the way
SYN out, RST back →
  refused
SYN, SYN-ACK, ACK, data, no
  reply → app or proxy
-w file.pcap for Wireshark

Write it up

Then write it up, with evidence rather than opinions. The symptom and when it started. What each check showed, for example SYNs leaving A but never reaching B, on captures from both sides. The cause, such as a security group change. The fix and how you verified it. And prevention: put security groups in Terraform with review, and add a synthetic check that tests this path every minute.

A good finding
  • symptom: A → B timed out since 14:02
  • evidence: SYNs leave A, none reach B (tcpdump both)
  • cause: SG change removed A's group from B's rule
  • fix + verification
  • prevention: SG in Terraform + review, synthetic check

Common mistakes

Mistakes. Starting with the application code before checking name, route and port. Testing from your laptop instead of from the machine that actually fails. Relying on ping. Changing several settings at once, so you never learn which one mattered. Trusting dig when the app reads etc hosts. And arguing from opinions instead of a packet capture.

Avoid these
  • starting at the app code
  • testing from the wrong machine (your laptop)
  • ping only
  • changing several things at once
  • trusting dig over getent
  • no capture, only opinions

Say it like this

In the interview: from service A's machine, I check that B's name resolves to the right address, that there is a route, and whether a TCP connection is refused or times out. A timeout sends me to firewalls and security groups on both sides, with counters or flow logs. If TCP connects, I test TLS with openssl, then the request with curl minus w and the proxy logs. If teams disagree, tcpdump on both ends decides.

In the interview
  • "From A: does B's name resolve
  • correctly? Is there a route? Does
  • nc connect: refused or timeout?
  • Timeout → firewalls and SGs on both sides, counters or flow
  • logs. Connected → TLS with openssl, then curl -w and the proxy logs. tcpdump to prove."

Interview questions

Q1How do you troubleshoot "service A cannot reach service B"?

From A: check DNS (getent/dig), route (ip route get, traceroute), port (nc -zv; ss -tlnp on B), firewalls/SGs, TLS (openssl s_client), then HTTP (curl -w, logs).

Q2What is mtr and when do you use it?

A continuous traceroute that shows loss and latency per hop; use it to find where on a path packets are lost or delayed.

Q3How does tcpdump help settle disputes between teams?

Captures on both ends show whether SYNs leave, arrive and get answered, pinpointing drops, refusals or app silence with evidence.

Q4What tools show which process listens on a port?

ss -tlnp (or ss -ulnp for UDP), lsof -i :PORT, and older netstat -tlnp.

Q5What are VPC flow logs useful for?

They record accepted and rejected flows per interface, so you can see whether a security group or NACL rejected specific traffic.

Q6Why test from the failing machine and not your laptop?

DNS, routes, firewalls and proxies differ per host and network; only the source machine reproduces the real path.