我怎样才能拥有一个具有多个 public IP 的 NAT 网关?

How can I have a single NAT Gateway with multiple public IPs?

我有一个项目涉及 运行 数百个从 Internet 获取数据的 Lambda 函数。

这些函数 运行 在我的 VPC 的私有子网中。

我希望这些功能不是它们的互联网流量都具有相同的 IP。

我的理解是我应该在 public 子网中创建一个 NAT 网关,但我找不到如何在该 NAT 网关上拥有多个 public IP 以进行某种随机化。

这可能吗?

应该如何实现这一目标?

不幸的是,这是不可能的,因为您不能将多个弹性 IP 与 public NAT 网关相关联。


一个public NAT网关只能使用1个分配的弹性IP,根据documentation:

The NAT gateway replaces the source IP address of the instances with the IP address of the NAT gateway. For a public NAT gateway, this is the elastic IP address of the NAT gateway.

You can associate exactly one Elastic IP address with a public NAT gateway.

To use a different Elastic IP address for your NAT gateway, you must create a new NAT gateway with the required address, update your route tables, and then delete the existing NAT gateway if it's no longer required.


拥有多个弹性 IP 和多个 NAT 网关也不太可行,因为弹性 IP 的默认(但可调整)限制是 5 per region & on NAT gateways, 5 per AZ

如果您使用 IaC(例如 Terraform、CloudFormation 等),您可以理论上 创建多个私有 NAT instances (after increasing the per-region service quota)但是我建议创建您自己的 NAT AMI在那种情况下。

将服务配额提高到数百个实例以及购买数百个 Elastic IPS 肯定会 发出一些警报。

如果可能,我希望重新构建您的应用程序(除非您的应用程序的性质需要它,在这种情况下,AWS 可能不是最佳选择)。

NAT 网关不可能,因为每个 NATG 只能附加一个 public IP。

但是,如果您愿意使用 NAT instances(更多的手动配置和管理开销),这是可能的。您可以设置多个 NAT 实例。相应地将您的 lambda 部署到多个私有子网中,每个子网都配置为转到一个 NAT 实例。