为什么来自私有子网的路由只能与 0.0.0.0 路由一起使用

问题描述 投票:0回答:1

我的架构:

EC2 in private subnet (10.0.0.0/24) --> NAT gateway in public subnet (10.0.0.8/24)

当我在私有子网中使用以下路由时,从 EC2 到互联网的连接不起作用。

10.0.0.0/24 nat-08a0fd199f0599e7c   Active  No
10.0.0.0/16 local   Active  No

如果我将私有子网中的路由表更改为此,它就可以工作:

0.0.0.0/0   nat-08a0fd199f0599e7c   Active  No
10.0.0.0/16 local   Active  No

但是这是为什么呢?两者似乎都与我相当。我的私有子网实际上是 10.0.0.0/24,我测试它的 IP 是 10.0.0.62

可达性分析器说:

rtb-0470933497a2054a2 (demo-private-routetable)
NO_ROUTE_TO_DESTINATION:
Route table rtb-0470933497a2054a2 does not have an applicable route to igw-01f02d81bd80fc493. See rtb-0470933497a2054a2.
amazon-web-services amazon-vpc
1个回答
0
投票

这条规则不正确10.0.0.0/24 nat-08a0fd199f0599e7c。您需要通过 NAT GW 路由除本地流量(本例中为 10.0.0.0/16)之外的所有流量,为此您需要使用 0.0.0.0/0 CIDR 范围,该范围基本上捕获“所有”流量。对于本地流量,使用 10.0.0.0/16,因为它具有更长的前缀,因此具有更大的路由优先级。

所以,这是正确的配置:

0.0.0.0/0   nat-08a0fd199f0599e7c   #Traffic outside the VPC (Internet)
10.0.0.0/16 local   #Internal VPC traffic (handled by the VPC router) 
© www.soinside.com 2019 - 2024. All rights reserved.