Connect To An Instance In A Private Subnet

Connect To An Instance In A Private Subnet

Connect to an instance in a private subnet

Hello Everyone

Welcome to CloudAffaire and this is Debjeet

In the last blog post, we have created an internet gateway and enabled internet connection to a public subnet.

https://cloudaffaire.com/create-an-internet-gateway/

In this blog post, we will learn how to connect to an instance that is hosted in a private subnet. If you enabled the internet to a public subnet and if your instance has a public IP then you can easily connect to the instance. But this is not the case for instances that are hosted in a private subnet. The private subnet is accessible within AWS infrastructure. In this demo, we will connect to an instance in private subnet from another instance in public subnet in the same VPC using agent forwarding.

We have two instances namely instance 1 (in private subnet with private IP 10.0.1.159) and instance 2 (in public subnet with private IP 10.0.2.159 and public IP 13.127.230.228).

Connect To An Instance In A Private Subnet

Connect to an instance in a private subnet:

Step 1: Open pageant in windows PC.

Connect To An Instance In A Private Subnet

Step 2: Click ‘Add Key’ and provide the key pair file for your instance in public subnet (instance 2).

Connect To An Instance In A Private Subnet

Step 3: Once the key is loaded, click ‘Close’.

Connect To An Instance In A Private Subnet

Step 4: Open putty in windows PC.

Connect To An Instance In A Private Subnet

Step 5: Provide the user name and DNS hostname of the instance in public subnet.

Connect To An Instance In A Private Subnet

Step 6: Navigate to ‘Auth’ located under SSH and check ‘Allow agent forwarding’ check box. Click ‘Open’.

Connect To An Instance In A Private Subnet

Step 7: You are now connected to the instance in public subnet (instance 2) through agent forwarding.

Connect To An Instance In A Private Subnet

Step 8: From instance 2 you can simply SSH to instance 1.

Connect To An Instance In A Private Subnet

Now we are connected to the instance in private subnet through an instance in public subnet using agent forwarding.

But instance 1 don’t have an internet access and if you try to connect to the internet from instance 1, it will fail.

Connect To An Instance In A Private Subnet

Hope you have enjoyed this article. You can enable outbound internet connection to a private subnet using a NAT Gateway which will be covered in the next blog post.

Leave a Reply

Close Menu