cloud-init not setting default route to NAT Gateway

0

The current setup is:

  • VPC with a public subnet 172.31.80.0/20
  • Routing Table has 0.0.0.0/0 directing to IGW
  • NAT in public subnet has private IP of 172.31.90.191

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 172.31.80.1 as the gateway, not the NAT.
DOPTS does not seem to have a field for setting the default gateway.

Question:
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.

질문됨 4년 전1021회 조회
1개 답변
0

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

Create VPC (Virtual Private Cloud) subnet 172.31.0.0/16
Create an IGW (Internet Gateway)
Create a public subnet within the VPC subnet 172.31.100.0/24
Create a public route table that has a route 0.0.0.0/0 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 0.0.0.0/0 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.

답변함 4년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠