# 子网中 IP 地址不足：子网没有足够的空闲 IP 地址来支持请求的 ENI 数量。

- **ID:** `aws/ec2-insufficient-ip-addresses`
- **领域:** aws
- **类别:** resource_error
- **验证级别:** ai_generated
- **修复率:** 82%

## 根因

VPC 子网已耗尽可用 IP 地址空间，阻止了新的 ENI 或 EC2 实例启动。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| EC2 API 2016-11-15 | active | — | — |
| AWS VPC CNI 1.12.0 | active | — | — |

## 解决方案

1. ```
   释放未使用的 ENI：使用 `aws ec2 describe-network-interfaces --filters Name=subnet-id,Values=subnet-xxx` 列出 ENI，并使用 `aws ec2 delete-network-interface --network-interface-id eni-xxx` 删除未附加的 ENI。
   ```
2. ```
   在同一个 VPC 中创建具有更大或额外 CIDR 块的新子网。向 VPC 添加辅助 CIDR：`aws ec2 associate-vpc-cidr-block --vpc-id vpc-xxx --cidr-block 10.0.2.0/24`。然后从新范围创建新子网。
   ```
3. ```
   减少 IP 消耗：使用需要较少 ENI 的较小 EC2 实例类型，或仅在必要时启用“分配公有 IP”，以避免额外的私有 IP 预留。
   ```

## 无效尝试

- **Delete the subnet and recreate it with a larger CIDR** — Deleting a subnet with running resources is impossible; you must first terminate all resources. (70% 失败率)
- **Manually assign Elastic IPs to free up private IPs** — Elastic IPs are public IPs and don't affect private IP address usage in subnets. (95% 失败率)
- **Increase subnet size via AWS Console (no such option)** — Subnet CIDR size is fixed at creation; it cannot be changed afterward. (100% 失败率)
