tblevins462/aws-secure-vpc-lab
GitHub: tblevins462/aws-secure-vpc-lab
本项目演示如何在AWS上构建带有公私子网、NAT与堡垒机的安全VPC,解决云网络隔离与可控互联网访问的实践问题。
Stars: 0 | Forks: 0
# AWS 安全 VPC 实验





本项目演示了如何创建一个安全的 AWS VPC 环境,包含公有子网和私有子网、互联网网关、NAT 网关、路由表,以及配置为安全访问的 EC2 实例。所有截图均存储在 `screenshots/` 目录中。
### 第一步 — 创建 VPC
创建了一个名为 `secure-vpc-lab-vpc` 的新 VPC,使用 CIDR 块 `10.0.0.0/16`,为多个子网和未来扩展提供了可扩展的地址空间。
**截图:**
`screenshots/01-vpc-created.png`
### 第二步 — 创建公有子网
创建了一个名为 `public-subnet-1` 的公有子网,使用 CIDR `10.0.1.0/24`。
启用了自动分配公有 IPv4 地址,以支持面向互联网的资源。
**截图:**
`screenshots/02-public-subnet.png`
### 第三步 — 创建私有子网
创建了一个名为 `private-subnet-1` 的私有子网,使用 CIDR `10.0.2.0/24`。
禁用了公有 IP 分配,以确保与互联网的隔离。
**截图:**
`screenshots/03-private-subnet.png`
### 第四步 — 互联网网关
创建了一个互联网网关(`secure-vpc-lab-igw`)并将其附加到 VPC,以允许公有资源访问互联网。
**截图:**
`screenshots/04-internet-gateway.png`
### 第五步 — 公有路由表
创建了一个公有路由表(`secure-vpc-lab-rtb-public`)并将其与公有子网关联。
添加了一条默认路由 `0.0.0.0/0`,指向互联网网关。
**截图:**
`screenshots/05-public-route-table.png`
### 第六步 — NAT 网关
在公有子网中创建了一个 NAT 网关(`secure-vpc-lab-natgw`)并附加了弹性 IP。
这允许私有实例在不暴露于公网的情况下安全地访问互联网进行更新。
**截图:**
`screenshots/06-nat-gateway.png`
### 第七步 — 私有路由表
创建了一个私有路由表(`secure-vpc-lab-rtb-private1-us-east-1a`)并将其与私有子网关联。
添加了一条默认路由 `0.0.0.0/0`,指向 NAT 网关。
**截图:**
`screenshots/07-private-route-table.png`
### 第八步 — EC2 实例
启动了两个 EC2 实例:
**公有 EC2(堡垒主机)**
- 子网:公有
- 公有 IP:是
- 用途:安全的 SSH 入口点
**私有 EC2**
- 子网:私有
- 公有 IP:否
- 用途:内部应用服务器
**截图:**
`screenshots/08-ec2-bastion.png`
`screenshots/09-ec2-private.png`
### 第九步 — 通过堡垒主机 SSH
验证了从本地机器使用密钥对 SSH 登录公有 EC2 实例。
**截图:**
`screenshots/10-ssh-into-bastion.png`
### 第十步 — 从堡垒主机 → 私有 EC2 SSH
将密钥对复制到堡垒主机,调整权限,并使用其私钥通过私有 IP SSH 登录私有 EC2 实例。
这验证了 VPC、子网、路由表、NAT 网关和安全组均已正确配置。
**截图:**
`screenshots/11-ssh-into-private.png`
### 第十一步 — 私有实例互联网测试
在私有 EC2 实例上运行 `sudo yum update -y`,以确认通过 NAT 网关的 outbound 互联网访问。
**截图:**
`screenshots/12-private-instance-internet-test.png`
### 架构图
以下是表示本实验所构建的安全 VPC 环境的高层架构图。
```
+-----------------------------+
| AWS Region (us-east-1)|
| |
| +---------------------+ |
| | VPC 10.0.0.0/16 | |
| | | |
| | +---------------+ | |
Internet | | | Public Subnet | | |
Gateway <------>|---|--| 10.0.1.0/24 | | |
(IGW) | | +-------+-------+ | |
| | | Bastion | |
| | | EC2 | |
| | +----------+ |
| | | |
| | +---------------+ | |
| | | Private Subnet| | |
| | | 10.0.2.0/24 | | |
| | +-------+-------+ | |
| | | Private | |
| | | EC2 | |
| | +----------+ |
| | | |
| +---------------------+ |
| |
+-----------------------------+
Key:
- Public Subnet routes 0.0.0.0/0 → IGW
- Private Subnet routes 0.0.0.0/0 → NAT Gateway → IGW
- SSH: Local → Bastion → Private EC2
```
### AI 工作流(摘要)
本节提供了 AI 在整个构建过程中如何提供协助的高层概述。
```
1. Architecture Planning
- AI helped validate CIDR sizing, subnet layout, and overall VPC design.
2. AWS Console Navigation
- Provided guidance for locating VPC, Subnets, Route Tables, NAT Gateway, and EC2 settings.
3. Troubleshooting
- Assisted with SSH issues, SCP upload errors, NAT routing validation, and AWS console inconsistencies.
4. Documentation
- Helped structure the README, step formatting, naming conventions, and screenshot organization.
5. GitHub Publishing
- Guided the creation of the repo, PAT authentication, and final push of all 12 screenshots.
```
完整详细的工作流程请参见:
**`ai-workflow.md`**
### 项目总结
本实验演示了如何使用 AWS 核心网络服务创建一个安全的生产风格 VPC 环境。
关键成果包括:
```
- Built a fully isolated VPC with public and private subnets
- Configured Internet Gateway and NAT Gateway for controlled internet access
- Implemented public and private route tables with correct routing logic
- Deployed a bastion host for secure SSH access into the VPC
- Launched a private EC2 instance with no public exposure
- Validated connectivity using SSH and NAT‑based internet access
- Documented the entire build with 12 screenshots and a full README
```
本项目反映了真实的云工程技能,包括网络设计、安全最佳实践和基础设施文档。
### 我的收获
本实验强化了多个重要的 AWS 网络与安全概念:
```
- How VPCs isolate cloud resources using CIDR blocks
- The difference between public and private subnets
- How Internet Gateways and NAT Gateways enable controlled internet access
- How route tables determine traffic flow inside a VPC
- How to use a bastion host for secure access to private resources
- How to test connectivity and validate NAT functionality
- How to structure and publish cloud projects on GitHub
```
这些技能可直接应用于真实的企业环境,并与 AWS Cloud Practitioner 和解决方案架构师助理级考试目标一致。
标签:AWS, Bash, Bastion Host, DPI, EC2, IaC, Internet Gateway, IPv4, NAT Gateway, VPC, 云安全最佳实践, 云架构, 云端实验环境, 公开子网, 公有云, 子网, 安全访问, 应用安全, 漏洞利用检测, 特权提升, 私有云, 私有子网, 网络安全, 网络架构, 网络隔离, 自动化部署, 路由表, 隐私保护