cloud-init not setting default route to NAT Gateway


The current setup is:

  • VPC with a public subnet
  • Routing Table has directing to IGW
  • NAT in public subnet has private IP of

Manually setting the NAT private IP as the default route ( using ip ro) in the EC2 allows the NAT Gateway to function as expected.
The issue is that at boot time the Amazon Linux 2 service cloud-init receives as the gateway, not the NAT.
DOPTS does not seem to have a field for setting the default gateway.

How can I make cloud-init receive the NAT IP as the setting for the default route?

In relation to this, the EC2 will also need a route for the AWS DNS at 169.something.
I suspect that a solution to the question will also help resolve this, but advice is welcome.

asked 3 years ago812 views
1 Answer

I solved this myself. This is what I had to do.

Create VPC (Virtual Private Cloud) subnet
Create an IGW (Internet Gateway)
Create a public subnet within the VPC subnet
Create a public route table that has a route pointing to the IGW
Add the public subnet to the public route table. The public subnet should now also use the public route table.
Create EC2s without access from the Internet must be in a private subnet that does not have a route to the IGW
Create an EIP (Elastic IP)
Create a NAT (NAT Gateway) in the private subnet and associate the EIP
Create a private route table for the private subnet and add a route of pointing to the NAT
The public and private subnets must both be within the VPC subnet but not overlapping.

The default GW from cloud-init now works for the EC2.

answered 3 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions