+86 135 410 16684Mon. - Fri. 10:00-22:00

AWS学习笔记-AWS VPC (Virtual Private Cloud)

AWS学习笔记-AWS VPC (Virtual Private Cloud)

AWS学习笔记-AWS VPC (Virtual Private Cloud)

整理一些設定 VPC 過程遇到的問題與心得。我設定的是案例官方文件中的 Scenario 3: VPC with Public and Private Subnets and Hardware VPN Access, 也就是包含

  1. 數個 Public Subnet
  2. 數個 Private
  3. 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-security-diagram

VPC 的 Size 可以調整?

不可以。CIDR 建立好之後就無法更動。

怎麼知道目標會走哪一個 route table?

看 subnet 設定在哪一個 route table.

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 等內部服務。

參閱: Your VPC with Subnets

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 突然無法對外連線了?

  1. 確認 Instance 的 Security Group 設定正確
  2. 確認 Instance 網卡 ENI 的 Security Group 設定正確. 如果有第二張網卡,那也要檢查.
  3. 找到 Instance 的 subnet 掛在哪一張 Route Table,確認 NAT Gateway 也在裡面.
  4. 找到 NAT Gateway 之後,找到他所屬的 Subnet 的 Route Table ,確認 Internet Gateway 在裡面

Public Subnet 裡的 EC2 無法對外連線了?

  1. 確認 Instance 本身有 EIP
  2. 檢查 Security Group, 確認 Outbound 正確
  3. 檢查 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