Lets assume I have a VPC (172.16.0.0/16
) with Public (172.16.0.0/24
) and Private (172.16.1.0/24
) subnets. Also I have one Internet Gateway (172.16.0.1/24
) and one NAT Gateway (172.16.1.x/24
). Note that the last bit is x
, as IP address is assigned dynamically.
When I spawn an instances in the public subnet the default gateway
is configured like so:
default via 172.16.0.1 dev eth0
When I spawn an instance in the private subnet I would like that instance had the default gateway
configured like so:
default via 172.16.1.x dev eth0
Note: x
in the last bit of the IP should match NAT-GW IP address.
At present I have to manually configure routing, thus change default gateway
and add explicit route to other subnet:
default via 172.16.1.x dev eth0
172.16.0.0/24 via 172.16.1.1 dev eth0
Things like these should be possible to configure via DHCP
, but aws
DHCP
seems to have a very limited set of settings.
EDIT - Route Tables:
Private subnet
172.16.0.0/16 local Active No
0.0.0.0/0 nat-id Active No
Public subnet
172.16.0.0/16 local Active No
0.0.0.0/0 igw-id Active No