Linux and networking
Debugging connectivity
When A cannot reach B, check each layer from the bottom up and write down what each one said. Timeouts and refusals point to different causes.
When one service cannot reach another, the fastest route is a checklist, not a guess. Go from the bottom up through the layers, and write down what each one told you. Most "the database is down" incidents end at one of the first three steps.
The checklist
- DNS. Does the name resolve to the address you expect? Use
dig. A private zone and a public zone with the same name is a classic cause. - Route. Does the subnet have a route to that address? A wrong route-table association after a Terraform change is common.
- Firewall on both sides. Check the security group or firewall on the destination for inbound, and on the source if its egress is restricted.
- Placement. Is the instance in a private subnet with no NAT, when it needs the internet?
- NACL ephemeral ports. A locked-down NACL can drop the replies.
- Overlapping ranges. Overlaps after peering make routes do something other than what you expect.
Reading the symptom
The error message says where to look.
- Timeout: the packets were dropped somewhere, by a filter, a missing route or a host with no listener.
- Connection refused: the packets reached a host, and its port is closed. The route and the filters worked.
Walking through an incident
An app times out connecting to rds.prod.internal:5432. The steps:
digreturns10.16.140.10, so DNS is fine.- The reachability analyser reports that
sg-dballows 5432 fromsg-app. The rule looks right. - The connection attempt used an ENI that belongs to an old instance, still tagged
sg-legacyafter a cutover. - VPC flow logs show
REJECTon the database's ENI.
The fix is to correct the security group membership. The database was never down.
Tools
- Reachability Analyzer (AWS) and Connectivity Test (GCP) check the path between two network interfaces.
- VPC Flow Logs record accepts and rejects. Turn them on before an incident, because they are the proof of which side denied the traffic.
- On the host:
nc -vz,curl -v,ip route getandssare the same tools as in Linux for engineers.
Common mistakes
- Declaring a service down from a timeout. A timeout usually means a filter, a route or a stale group, not a crashed service.
- Checking only one side's firewall. A rule on the destination does not help if the source's egress is restricted.
- Turning on flow logs during the incident. Enable them in advance.
Check yourself
- A client gets "connection refused" rather than a timeout. What does that tell you? Answer: The packets reached a host, so the route and filters worked. The port on that host is closed or has no listener.
- Why enable VPC flow logs before an incident? Answer: They record accepts and rejects, which is the evidence of which side denied the traffic.
Key takeaways
- Debug bottom-up: DNS, route, firewall on both sides, placement, NACL ports, overlaps.
- A timeout points at the path. A refusal points at the listener.
- Reachability Analyzer and flow logs turn guesses into evidence.
Further learning
The host-side commands in this page work the same way as the ones in Linux for engineers. The hub for the whole topic is cloud networking and VPCs.
Related
Linux for engineers
The parts of Linux you touch in production, from shell pipelines and systemd services to permissions, disks, network debugging commands and safe remote access.
Cloud networking and VPCs
VPCs, subnets, routing, NAT, security groups and private connectivity in AWS and GCP, plus a three-AZ reference architecture and how to debug when A cannot reach B.
Network tools
How to check the claims in the networking pages with ping, mtr, ss and tcpdump, including how to read a handshake in a capture and what each timestamp means.