Create a public subnet
Welcome to CloudAffaire and this is Debjeet
In the last blog post, we have created a private subnet and explicitly associated it with a custom route table.
In this blog post, we are going to convert our private subnet (subnet 2) into a public subnet by allocation a public IP address and an Internet gateway. I am dividing this in two parts and in the first part we will allocate a public IP address and DNS hostname to an EC2 instance in this subnet. And in the next blog will create the internet gateway and enable internet access. Below is the configuration diagram for this demo.
Create a public subnet:
Step 1: Login to AWS console and navigate to ‘VPC’.
Step 2: Navigate to ‘Subnets’ and select the new subnet (subnet 2).
Note: Auto-assign public IPv4 is disabled for this subnet. We will enable auto assign public IPv4 so that any new instance created in this subnet can get a new public IPv4 address. You can also use Elastic IP address instead for the public address that will be persistent.
Step 3: Click ‘Modify auto-assign IP settings’ located under ‘Actions’.
Step 4: Check ‘Auto-assign IPv4’ and click ‘Save’.
Next, create an EC2 instance using this VPC and subnet (subnet 2)
Observe: A new public IPv4 address has been assigned to your new EC2 instance. But the Public DNS field is empty. If you create your VPC manually then only DNS resolution is enabled, and DNS hostname is disabled. If instead, you had created, you VPC using Launch VPC wizard both settings would have been enabled.
Next, we are going to enable DNS hostname for our VPC.
Step 5: Navigate to ‘Your VPCs’ and select your VPC. From ‘Actions’ click ‘Edit DNS hostnames’.
Step 6: Check ‘DNS hostnames’ and click ‘Save’.
A success message will be displayed. Click ‘Close’.
DNS hostnames successfully enabled for your VPC.
Your instance will also get a new Public DNS automatically.
But if we ping our EC2 instance using this public DNS or try to connect to it. It will fail because no internet gateway is associated with our VPC yet.
Cleanup: Delete your EC2 instance and then navigate to ‘Your VPCs’, select your VPC and from action click ‘Delete’.
Note: We will use this same VPC and existing configuration in upcoming blogs, hence if you wish to continue then don’t delete your VPC.
Hope you have enjoyed this blog post. In the next blog post, we are going to create an Internet Gateway and attach it to this VPC.
To get more details on VPC, please refer below AWS documentation