1. 安装aws cli,查看站内文章
https://www.starbucket.com.cn/blog/%E5%B8%B8%E7%94%A8%E7%BC%96%E8%AF%91%E5%B7%A5%E5%85%B7%E7%8E%AF%E5%A2%83
2. 创建双栈 VPC, 默认CIDR(192.168.0.0/16)
aws ec2 create-vpc --region ap-east-1 --cidr-block 192.168.0.0/16 --amazon-provided-ipv6-cidr-block --tag-specifications "ResourceType=vpc,Tags=[{Key=Name,Value=dualstack-vpc}]"
3. 开 DNS
aws ec2 modify-vpc-attribute --region ap-east-1 --vpc-id vpc-xxx --enable-dns-support
aws ec2 modify-vpc-attribute --region ap-east-1 --vpc-id vpc-xxx --enable-dns-hostnames
4. 查 Amazon 分配的 IPv6 /56
aws ec2 describe-vpcs --region ap-east-1 --vpc-ids vpc-xxx --query "Vpcs[0].Ipv6CidrBlockAssociationSet[0].Ipv6CidrBlock" --output text
假设结果是 2406:da1e:xxxx:yy00::/56,三个子网 IPv6 写成:
- 2406:da1e:xxxx:yy0a::/64(对应 192.168.10.0/24)
- 2406:da1e:xxxx:yy14::/64(对应 192.168.20.0/24)
- 2406:da1e:xxxx:yy1e::/64(对应 192.168.30.0/24)
5. 创建双栈子网(三个 AZ)
aws ec2 create-subnet --region ap-east-1 --vpc-id vpc-xxx --availability-zone ap-east-1a --cidr-block 192.168.10.0/24 --ipv6-cidr-block 2406:da1e:xxxx:yy0a::/64 --tag-specifications "ResourceType=subnet,Tags=[{Key=Name,Value=subnet-10}]"
aws ec2 create-subnet --region ap-east-1 --vpc-id vpc-xxx --availability-zone ap-east-1b --cidr-block 192.168.20.0/24 --ipv6-cidr-block 2406:da1e:xxxx:yy14::/64 --tag-specifications "ResourceType=subnet,Tags=[{Key=Name,Value=subnet-20}]"
aws ec2 create-subnet --region ap-east-1 --vpc-id vpc-xxx --availability-zone ap-east-1c --cidr-block 192.168.30.0/24 --ipv6-cidr-block 2406:da1e:xxxx:yy1e::/64 --tag-specifications "ResourceType=subnet,Tags=[{Key=Name,Value=subnet-30}]"
6. 启动时自动分配 IPv6 (三个AZ都需要)
aws ec2 modify-subnet-attribute --region ap-east-1 --subnet-id subnet-xxx10 --assign-ipv6-address-on-creation
7. IPv4 出网:Internet Gateway
aws ec2 create-internet-gateway --region ap-east-1 --tag-specifications "ResourceType=internet-gateway,Tags=[{Key=Name,Value=dualstack-igw}]"
aws ec2 attach-internet-gateway --region ap-east-1 --vpc-id vpc-xxx --internet-gateway-id igw-xxx
8. IPv6 出网:Egress-only Internet Gateway
aws ec2 create-egress-only-internet-gateway --region ap-east-1 --vpc-id vpc-xxx
- 记下 EgressOnlyInternetGatewayId。
9. 主路由表加默认路由
aws ec2 describe-route-tables --region ap-east-1 --filters "Name=vpc-id,Values=vpc-xxx" "Name=association.main,Values=true" --query "RouteTables[0].RouteTableId" --output text
aws ec2 create-route --region ap-east-1 --route-table-id rtb-xxx --destination-cidr-block 0.0.0.0/0 --gateway-id igw-xxx
aws ec2 create-route --region ap-east-1 --route-table-id rtb-xxx --destination-ipv6-cidr-block ::/0 --egress-only-internet-gateway-id eigw-xxx
公网 IPv4 实例还要给对应子网开自动公网 IP:
aws ec2 modify-subnet-attribute --region ap-east-1 --subnet-id subnet-xxx --map-public-ip-on-launch
- 安全组入站要单独加 IPv6(::/0 或你的前缀),默认往往只有 IPv4。
10. 创建EC2服务器

- 自动分配(公有IP/IPV6)已启用

Comments & discussion
The first comment in each thread opens a topic. Signed-in readers can keep the conversation going under that topic.
No comments yet. Sign in to start a topic.
Start a new topic
Sign in to start a topic or join the discussion.