Introduction
AWS Security Groups act as virtual firewalls controlling inbound and outbound traffic to EC2 instances, RDS databases, and other resources. When traffic is blocked, services can't communicate, causing connection timeouts and application failures.
Symptoms
Connection timeout:
```bash $ curl -v http://ec2-ip.compute.amazonaws.com:80
curl: (28) Failed to connect to IP port 80: Connection timed out ```
SSH connection refused:
```bash $ ssh -i key.pem ec2-user@ec2-ip.compute.amazonaws.com
ssh: connect to host IP port 22: Connection refused ```
Application connectivity failure:
```bash $ telnet ec2-ip 3306
Trying IP... telnet: Unable to connect to remote host: Connection timed out ```
Common Causes
- 1.Inbound rule missing - No rule allows traffic on required port
- 2.Wrong source specified - Source IP/CIDR doesn't include your IP
- 3.Wrong port configured - Rule allows different port
- 4.Protocol mismatch - TCP rule but UDP traffic
- 5.Rule order issue - Specific deny overrides allow (NACLs)
- 6.Multiple security groups - Conflicting rules across groups
- 7.Network ACL blocking - Subnet NACL more restrictive
Step-by-Step Fix
- 1.Check logs for specific error messages
- 2.Verify configuration settings
- 3.Test network connectivity
- 4.Review recent changes
- 5.Apply corrective action
- 6.Verify the fix
Step 1: Check Security Group Rules
```bash # Get security group details aws ec2 describe-security-groups \ --group-ids sg-12345678 \ --query 'SecurityGroups[*].[GroupName,GroupId]'
# List inbound rules aws ec2 describe-security-groups \ --group-ids sg-12345678 \ --query 'SecurityGroups[*].IpPermissions' ```
Step 2: Check Instance Security Groups
```bash # Get security groups attached to instance aws ec2 describe-instances \ --instance-ids i-12345678 \ --query 'Reservations[*].Instances[*].SecurityGroups[*].[GroupId,GroupName]'
# Instance can have multiple security groups # Traffic allowed if ANY security group allows it ```
Step 3: Verify Inbound Rules for Port
bash
# Check specific port
aws ec2 describe-security-groups \
--group-ids sg-12345678 \
--query 'SecurityGroups[*].IpPermissions[?FromPort==80 && ToPort==80`]'
# Check port range
aws ec2 describe-security-groups \
--group-ids sg-12345678 \
--query 'SecurityGroups[*].IpPermissions[?FromPort>=80 && ToPort<=80]'
```
Step 4: Check Source CIDR Range
```bash # Get your current IP curl -s ifconfig.me
# Check if your IP is in allowed range aws ec2 describe-security-groups \ --group-ids sg-12345678 \ --query 'SecurityGroups[*].IpPermissions[*].IpRanges[*].CidrIp'
# Common sources: # - 0.0.0.0/0: All IPs (public access) # - 10.0.0.0/8: Private VPC range # - YOUR_IP/32: Specific single IP ```
Step 5: Add Missing Inbound Rule
```bash # Add inbound rule for HTTP aws ec2 authorize-security-group-ingress \ --group-id sg-12345678 \ --protocol tcp \ --port 80 \ --cidr 0.0.0.0/0
# Add inbound rule for SSH from specific IP aws ec2 authorize-security-group-ingress \ --group-id sg-12345678 \ --protocol tcp \ --port 22 \ --cidr YOUR_IP/32
# Add inbound rule for range aws ec2 authorize-security-group-ingress \ --group-id sg-12345678 \ --protocol tcp \ --port 80-443 \ --cidr 0.0.0.0/0 ```
Step 6: Check Outbound Rules
```bash # Check outbound rules aws ec2 describe-security-groups \ --group-ids sg-12345678 \ --query 'SecurityGroups[*].IpPermissionsEgress'
# Default security group allows all outbound traffic # Custom groups may restrict outbound ```
Add outbound rule if missing:
aws ec2 authorize-security-group-egress \
--group-id sg-12345678 \
--protocol tcp \
--port 443 \
--cidr 0.0.0.0/0Step 7: Check Network ACL
```bash # Get subnet's Network ACL aws ec2 describe-network-acls \ --filters Name=association.subnet-id,Values=subnet-12345678 \ --query 'NetworkAcls[*].[NetworkAclId,Entries]'
# NACL rules: # - Have priority numbers (lower = higher priority) # - Can explicitly deny traffic # - Must have allow rules for both inbound and outbound
# Check if NACL blocks traffic
aws ec2 describe-network-acls \
--network-acl-id acl-12345678 \
--query 'NetworkAcls[*].Entries[?PortRange.From==80]'
```
Step 8: Verify Protocol
```bash # Check protocol in rule aws ec2 describe-security-groups \ --group-ids sg-12345678 \ --query 'SecurityGroups[*].IpPermissions[*].[IpProtocol,FromPort,ToPort]'
# Protocols: # - tcp: TCP traffic # - udp: UDP traffic # - icmp: Ping/ICMP # - -1: All protocols
# Add UDP rule if needed aws ec2 authorize-security-group-ingress \ --group-id sg-12345678 \ --protocol udp \ --port 53 \ --cidr 10.0.0.0/8 ```
Step 9: Test Connectivity
```bash # After adding rules, test connection # SSH test ssh -i key.pem ec2-user@PUBLIC_IP
# HTTP test curl -v http://PUBLIC_IP:80
# Port test telnet PUBLIC_IP PORT
# Ping test (requires ICMP rule) ping PUBLIC_IP ```
Step 10: Remove Incorrect Rules
```bash # Remove incorrect rule aws ec2 revoke-security-group-ingress \ --group-id sg-12345678 \ --protocol tcp \ --port 22 \ --cidr OLD_IP/32
# Remove all rules from specific source aws ec2 revoke-security-group-ingress \ --group-id sg-12345678 \ --ip-permissions '[{"IpProtocol":"tcp","FromPort":80,"ToPort":80,"IpRanges":[{"CidrIp":"0.0.0.0/0"}]}]' ```
Common Port Reference
| Service | Port | Protocol |
|---|---|---|
| SSH | 22 | TCP |
| HTTP | 80 | TCP |
| HTTPS | 443 | TCP |
| MySQL | 3306 | TCP |
| PostgreSQL | 5432 | TCP |
| Redis | 6379 | TCP |
| DNS | 53 | UDP/TCP |
| RDP | 3389 | TCP |
Verification
bash
# After adding rules, verify connectivity
# Check security group
aws ec2 describe-security-groups \
--group-ids sg-12345678 \
--query 'SecurityGroups[*].IpPermissions[?FromPort==REQUIRED_PORT`]'
# Test connection curl -v http://INSTANCE_IP:PORT
# Should connect successfully ```
Related Issues
- [Fix AWS VPC Peering Connection Not Working](/articles/fix-aws-vpc-peering-connection-not-working)
- [Fix AWS EC2 Instance Not Reachable](/articles/fix-aws-ec2-instance-not-reachable)
- [Fix AWS Network ACL Blocking Traffic](/articles/fix-aws-network-acl-blocking-traffic)
Related Articles
- [Technical troubleshooting: Fix Certificate Chain Incomplete SSL Validation Is](certificate-chain-incomplete-ssl-validation)
- [Fix Ddos Attack Mitigation Waf Rate Limiting Issue in Network Security](ddos-attack-mitigation-waf-rate-limiting)
- [Fix DNS Hijacking Spoofing Attack Issue in Network Security](dns-hijacking-spoofing-attack)
- [Fix firewall iptables rules not persisting across reboot Issue in Network-Security](firewall-iptables-rules-not-persisting-across-reboot)
- [Fix firewall rule blocking legitimate traffic Issue in Network-Security](firewall-rule-blocking-legitimate-traffic)
<script type="application/ld+json"> { "@context": "https://schema.org", "@type": "TechArticle", "headline": "Fix AWS Security Group Blocking Traffic", "description": "Troubleshoot AWS security group blocking issues. Fix inbound rules, port configuration, and source IP ranges.", "url": "https://www.fixwikihub.com/fix-aws-security-group-blocking", "publisher": { "@type": "Organization", "name": "FixWikiHub", "url": "https://www.fixwikihub.com" }, "author": { "@type": "Person", "name": "FixWikiHub Editorial Team" }, "datePublished": "2026-04-01T23:51:08.751Z", "dateModified": "2026-04-01T23:51:08.751Z" } </script>