Security Group Rules and Syntax
What You'll Learn
You'll learn the exact syntax for writing security group rules, including how to specify protocols, port ranges, and traffic sources or destinations.
Understanding Rule Components
Every security group rule consists of four essential parts:
1. Direction: Inbound (ingress) or outbound (egress)
2. Protocol: TCP, UDP, ICMP, or "all"
3. Port Range: Single port (22), range (1024-65535), or all ports
4. Source/Destination: IP address, CIDR block, or another security group
Think of a security group rule like a bouncer's checklist: "Allow people (protocol) from this neighborhood (source) to enter through this door (port) into the building (instance)."
Rule Syntax Pattern
Rules follow this logical format:
[Allow/Deny] [Protocol] traffic on [Port/Port Range] from/to [Source/Destination]
For example:
- "Allow TCP traffic on port 443 from 0.0.0.0/0" (HTTPS from anywhere)
- "Allow TCP traffic on port 22 from 203.0.113.0/24" (SSH from specific network)
- "Allow all traffic from sg-abc123" (all protocols from another security group)
Common Protocol and Port Combinations
- SSH: TCP port 22
- HTTP: TCP port 80
- HTTPS: TCP port 443
- RDP: TCP port 3389
- Custom application: TCP/UDP on your chosen port
The source "0.0.0.0/0" means "anywhere on the internet," while specific CIDR blocks restrict access to known networks.
Key Concepts
Security groups are stateful: when you allow inbound traffic, the response is automatically allowed back out—you don't need to create matching outbound rules.
Key Takeaway: Security group rules use a standard syntax combining protocol type, port numbers, and source/destination identifiers (IP ranges or other security groups) to precisely control traffic flow.