安全组与网络 ACL
通过控制实例和子网的入站与出站流量,实现强大的网络级安全防护。
安全组与网络 ACL 是 CoddyKit 上的免费 AWS for Backend Developers (EC2, S3, RDS, Lambda) 课时。 这是第 2 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 AWS for Backend Developers (EC2, S3, RDS, Lambda) 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 AWS for Backend Developers (EC2, S3, RDS, Lambda) 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Guarding Your AWS Network
Securing your AWS resources is crucial. Think of your cloud environment as a house – you need good locks on the doors and windows.
In AWS, two key services act as virtual firewalls to protect your instances and subnets: Security Groups and Network Access Control Lists (NACLs).
Instance-Level Firewalls
A Security Group acts as a virtual firewall for your EC2 instances (or other resources like RDS instances or Load Balancers).
It controls inbound and outbound traffic at the instance level. When you launch an EC2 instance, you associate one or more security groups with it.
Security Group Rules
Security Groups have rules that specify which traffic is allowed to reach your instances (inbound) and which traffic your instances can send out (outbound).
- Inbound Rules: Define what traffic can enter your instance.
- Outbound Rules: Define what traffic can leave your instance.
By default, outbound traffic is usually allowed, but inbound traffic is denied.
Stateful Protection
A key characteristic of Security Groups is that they are stateful.
This means if you allow an inbound request (e.g., a web request to your server), the Security Group automatically allows the corresponding outbound response to flow back, even if there isn't an explicit outbound rule for it.
It remembers the connection's "state."
What are Network ACLs (NACLs)?
A Network Access Control List (NACL) acts as a virtual firewall for your subnets. It controls traffic entering and exiting the entire subnet.
Unlike Security Groups, NACLs are applied to subnets, meaning all instances within that subnet are subject to its rules.
NACL Rules Explained
NACLs have numbered rules that are evaluated in order, from lowest to highest. When a rule matches traffic, it's applied, and no further rules are evaluated.
NACLs can explicitly allow or deny traffic. Every NACL also has a default deny rule (*) at the end to catch any unmatched traffic.
Stateless Protection
Another key difference: NACLs are stateless.
If you allow inbound traffic, you MUST explicitly create a separate outbound rule to allow the response traffic to return. If you don't, the response will be blocked.
This means you need rules for both directions for any connection.
Key Differences at a Glance
- Scope: SG for instances, NACL for subnets.
- State: SG is stateful, NACL is stateless.
- Rules: SG only allows, NACL allows AND denies.
- Evaluation: SG evaluates all rules, NACL evaluates by rule number (lowest first).
- Default: SG denies inbound, allows outbound. NACL allows all by default, then denies all with * rule.
Layered Security
It's best practice to use both Security Groups and NACLs together for layered security:
- Use NACLs to broadly filter traffic at the subnet boundary, blocking known malicious IPs or port ranges.
- Use Security Groups to provide fine-grained control for specific instances, allowing only necessary traffic to reach them.
This creates a robust defense-in-depth strategy.
Understanding the Layers
You have an EC2 instance in a public subnet. You want to allow SSH (port 22) and HTTP (port 80) traffic to reach it from anywhere, and block all other incoming traffic.
Securing Your Network
Great job! You've learned about two fundamental AWS networking security tools:
- Security Groups: Stateful firewalls for instances, allowing specific inbound/outbound traffic.
- Network ACLs (NACLs): Stateless firewalls for subnets, allowing/denying traffic based on rule order.
Understanding these helps you build a strong, multi-layered defense for your AWS resources. Next, we'll explore IAM Roles and Policies for fine-grained access control.
常见问题解答
「安全组与网络 ACL」课时是免费的吗?
是的 — 「安全组与网络 ACL」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 AWS for Backend Developers (EC2, S3, RDS, Lambda) 课程的其余内容,请升级到 CoddyKit PRO。 AWS for Backend Developers (EC2, S3, RDS, Lambda) 课程共包含 4 节课。
「安全组与网络 ACL」这节课中我会学到什么?
通过控制实例和子网的入站与出站流量,实现强大的网络级安全防护。 你通过在浏览器中直接运行的动手代码来练习 AWS for Backend Developers (EC2, S3, RDS, Lambda),全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 AWS for Backend Developers (EC2, S3, RDS, Lambda) 需要有经验吗?
无需任何先前经验。CoddyKit 上的 AWS for Backend Developers (EC2, S3, RDS, Lambda) 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 2 节课,共 4 节。
「安全组与网络 ACL」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 AWS for Backend Developers (EC2, S3, RDS, Lambda) 课中编写并运行代码吗?
能。每节 AWS for Backend Developers (EC2, S3, RDS, Lambda) 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。
此课程中的所有课时
- VPC、子网与路由表
- 安全组与网络 ACL
- IAM 角色与策略
- VPC 端点与私有连接