Sub topic 14
Troubleshooting blocked connections
This chapter assumes you know TCP/IP basics, CIDR notation, and how a VPC, subnets and EC2 instances fit together. You should also know that security group rules are allow-only and stateful, and that several groups on one interface add up.
Start with the symptom
The way a connection fails tells you where to look. A security group blocks traffic by dropping packets silently, so you never get a "denied" reply.
| Symptom | Likely cause |
|---|---|
| Connection hangs, then times out | A security group, network ACL or route is dropping packets |
| "Connection refused" right away | Traffic reached the host, but nothing listens on that port |
| Works from one client, fails from another | The source CIDR or referenced group in the rule does not match the failing client |
| Inbound works, outbound calls hang | The outbound rules lack an allow for that destination and port |
A refused connection is not a security group problem. Look at the application and its listening port instead.
Work through the path
- Identify the interfaces. Security groups attach to network interfaces, so find the groups on both the source and the destination interface. An instance can have several groups, and the effective rule set is the union of all of them.
- Check the destination's inbound rules. Confirm that some attached group allows the protocol, port and source. If the source is a security group, the client must have that group attached to its interface. Being in the same subnet is not enough.
- Check the source's outbound rules. The default group allows all outbound traffic. A custom group that removed that rule can block the connection before it leaves.
- Check network ACLs. They are stateless, so they must allow the request and the return traffic on ephemeral ports.
- Check routes, the host firewall and the listener. A missing route or an OS firewall such as
iptablesproduces the same timeout.
Inspect the rules
Read the real configuration instead of trusting memory. This lists the groups attached to an instance:
aws ec2 describe-instances \
--instance-ids i-0123456789abcdef0 \
--query 'Reservations[].Instances[].NetworkInterfaces[].[NetworkInterfaceId,Groups[].GroupId]'Then list the inbound rules of one group:
aws ec2 describe-security-group-rules \
--filters Name=group-id,Values=sg-0123456789abcdef0 \
--query 'SecurityGroupRules[?IsEgress==`false`].[IpProtocol,FromPort,ToPort,CidrIpv4,ReferencedGroupInfo.GroupId]'Common mistakes
- Wrong source address. A rule for
203.0.113.25/32fails when your public IP changes. Compare it with the address you actually connect from. - Rule edited in the wrong group. Check the group ID, not just the name. The same name can exist in different VPCs.
- Port range mismatch. A rule for 8080 does not cover 8443.
- Using a public address to reach a private target. A client in the same VPC that connects through a public IP may be matched against the wrong source address. Use the private address and a group reference.
- Protocol mismatch. A TCP rule does not allow ping, which is ICMP.
Exercise
A web instance in sg-web calls an application instance in sg-app on TCP port 8080 and the request times out. The sg-app inbound rule allows TCP 8080 from sg-web, and the web instance has only sg-web attached. Name two other places to check.
Show answer
Check the outbound rules of sg-web, since a custom group may have removed the allow-all outbound rule. Check the network ACLs on both subnets, which must allow the request and the return traffic on ephemeral ports. The routes, the host firewall on the application instance and whether the application listens on 8080 are also valid answers.