AWS学习笔记-AWS VPC (Virtual Private Cloud)
导出 PDF
浅色排版、带版权水印,可在打印窗口另存为 PDF
整理一些設定 VPC 過程遇到的問題與心得。我設定的是案例官方文件中的 Scenario 3: VPC with Public and Private Subnets and Hardware VPN Access, 也就是包含
- 數個 Public Subnet
- 數個 Private
- VPN to own IT infrastructure over an IPSec VPN tunnel
同時,這個規劃也考慮了 AZ 以及開發時的各種環境需求,像是 Dev / Test / Staging / Production … 等環境,過程中遇到的問題都整理在這裡。
如何將兩個 VPC 串接
- 使用 AWS Peering,就可以打通兩個 VPC. see VPC Peering
- 可以跨 AWS Account,但是不能跨 Region
如何限制 VPC Peering 之間的存取控制?
利用以下兩個
- Route Table: 控制目標要走哪一個 gateway / peering connections
- Network ACLs: 限制進出的 port, 有點像是 iptable / security group, 但是控制的是針對 subnet
流程上參考下圖:
VPC 的 Size 可以調整?
不可以。CIDR 建立好之後就無法更動。
怎麼知道目標會走哪一個 route table?
看 subnet 設定在哪一個 route table.
推荐
推荐服务 · 一站式办理
由云市场认证服务商承接,下单后按需沟通交付。
腾讯云市场
NGINX / APACHE / TOMCAT / IIS 证书配置 · SSL证书安装
各服务器环境 SSL 证书安装配置,教程看不懂?直接交给服务商办。
查看服务 →
阿里云市场
代购 SSL 证书 · DigiCert / GeoTrust / RapidSSL 单域名 DV
单域名 DV 证书代购,主流品牌可选,比官网渠道更省。
查看服务 →
阿里云市场
Wildcard 通配符 SSL 证书安装部署续费申请
一张通配符保护全部一级子域名,含安装部署与续费服务。
查看服务 →
腾讯云市场
SSL证书申请+配置 · 宝塔/WDCP 面板全站加密(OV 企业单域名等规格)
付费证书云上签发、一键部署到宝塔/WDCP 站点,OV 企业单域名可选。
查看服务 →
阿里云市场
企业级 EV / OV 证书与代码、驱动签名服务
SSL EV/OV 证书 + 软件代码签名、驱动签名,企业级一站式办理。
查看服务 →
阿里云市场
GlobalSign 代码签名证书服务(OV/EV 企业版)
对 exe/dll/驱动等软件做数字签名,消除「未知发布者」警告,企业版含申请代办。
查看服务 →
阿里云市场
HTTPS证书申请 · SSL证书安装部署 · 证书续费
证书过期、部署报错、需要续期?申请+部署+续费一站式办理。
查看服务 →
云市场服务直达
阿里云市场
腾讯云市场
- APP/小程序 HTTPS · SSL网站加密证书 · CA证书配置
- NGINX / APACHE / TOMCAT / IIS 证书配置 · SSL证书安装
- SSL证书安装服务 · 腾讯云 HTTPS 部署 · 证书过期更新
华为云商店
route table 跟 subnet 關係是一對一,也就是一個 subnet 只允許在一張 route table.
現有的 EC2 Instance ENI 可否更換 subnet?
- 可以更換在同一個 AZ 的 Subnet,不同 AZ 則不可以。
- 第一張 Primary NI 不可以 detach.
AWS 文件常看到 Public Subnet & Private Subnet 是什麼意思?
- Public Subnet:
- 指的是 subnet 掛的 route table, destination 到 Public Network 走 Internet Gateway
- 裡面的機器透過 EIP 出去 / 進來。所以 這個網段的 Instance 都要有 EIP.
- 通常是開放給外面連線的服務或者網路設備,像是 VPN, Proxy, NAT Instance … etc.
- Private Subnet:
- 指的是 subnet 掛的 route table, destination 到 Public Network 沒有 走 Internet Gateway, 而是走 NAT Gateway
- 可出去外面,但是外面不可進來,像是走 NAT Gateway 或者是其他 VPN Gateway.
- 這個網段不需要有 EIP 就可以出去。
- 通常是 DB / Application Server 等內部服務。
Network ACL 和 Security Group 有什麼不一樣?
- Network ACLs:
- 針對 VPC Subnet
- 可以控制 Inbound / Outbound
- 有 Allow / Deny
- Security Group:
- 針對 EC2 Instance / ENI
- 可以控制 Inbound / Outbound (同 ACLs)
- 只有 Allow, 沒有 Deny
詳細參閱:
Private Subnet 裡的 EC2 突然無法對外連線了?
- 確認 Instance 的 Security Group 設定正確
- 確認 Instance 網卡 ENI 的 Security Group 設定正確. 如果有第二張網卡,那也要檢查.
- 找到 Instance 的 subnet 掛在哪一張 Route Table,確認 NAT Gateway 也在裡面.
- 找到 NAT Gateway 之後,找到他所屬的 Subnet 的 Route Table ,確認 Internet Gateway 在裡面
Public Subnet 裡的 EC2 無法對外連線了?
- 確認 Instance 本身有 EIP
- 檢查 Security Group, 確認 Outbound 正確
- 檢查 Subnet 的 Route Table,確認裡面 destination 有 Internet Gateway
VPC NAT Gateway 是否有單點 (SPOF) 問題?
建立 NAT Gateway 時,要選擇 Subnet,就等於表示此 Gateway 在 Subnet 所在的 AZ。如果此 AZ 出問題,Route Table 共用此 Gateway,其他的 AZ 將無法出去。參考:NAT Gateway Basics 以下的描述:
If you have resources in multiple Availability Zones and they share one NAT gateway, in the event that the NAT gateway’s Availability Zone is down, resources in the other Availability Zones lose Internet access. To create an Availability Zone-independent architecture, create a NAT gateway in each Availability Zone and configure your routing to ensure that resources use the NAT gateway in the same Availability Zone.
Reference
- Security in Your VPC
- Recommended Network ACL Rules for Your VPC
- VPC with Public and Private Subnets and Hardware VPN Access
- Comparison of Security Groups and Network ACLs
- VPC FAQs
- Introduction to AWS VPC, Guidelines, and Best Practices
