Test Connection

Checking connection

There are many ways to connect to EC2, you can refer to connect EC2 with PuTTY. In the lab, we use MobaXterm to connect EC2

  1. Download MobaXterm

Create VPC

  1. Go to EC2 page
  • Select Instances
  • Select EC2 Public
  • Select Details
  • View Public IPv4 address

Create VPC

  1. After downloading MobaXterm, extract and open
  • Select Session

Create VPC

  1. In the Session settings interface
  • Select SSH

Create VPC

  1. In the Session settings interface
  • Remote host, enter Public IPv4 address
  • Specify username, enter ec2-user
  • Use private key, choose the path of aws-keypair.pem created and download it at EC2 creation.

Create VPC

  1. Connection successful.

Create VPC

  1. Check the connection to the internet of EC2 Public, we execute the command:
ping amazon.com -c5

Create VPC

Connect to EC2 Private server and check internet connection.

  1. Access to EC2
  • Select Instances
  • Select EC2 Private
  • Select Details
  • Select Private IPv4 addresses

Create VPC

  1. Do a ping <EC2 Private’s private IP address> to test the connection from the EC2 Public server to the EC2 Private server. We test the connection between two EC2 instances with the command:
ping 10.10.4.105 -c5

Create VPC

  1. EC2 Private will not have a public IP address because we are not assigning this server a public IP. To be able to ssh into EC2 Private, we will make an ssh connection from EC2 Public through EC2 Private private IP address
  • Download the pscp tool to the same folder containing the aws-keypair.ppk file to copy the aws-keypair.pem file from our machine to EC2 Public.

You download a RSA and DSA key generation utility as puttygen.exe

  1. We use puttygen.exe to generate key
  • Select Load

Create VPC

  1. Select aws-keypair.pem
  • Select OK
  • Select Save private key with the name aws-keypair.ppk

Create VPC

  1. Complete the generation key

Create VPC

  1. Launch Command Prompt. Change the path to the folder you just downloaded pscp. Run the command below to upload the aws-keypair.pem file to the /home/ec2-user/ directory of the EC2 Public server.
  • You will need to replace the public IP address of the EC2 Public parameter before running the command.
pscp -i aws-keypair.ppk aws-keypair.pem ec2-user@<EC2 PUBLIC public IP address>:/home/ec2-user/

Create VPC

  1. Access to EC2
  • Select Instances
  • Select EC2 Public
  • Select Details
  • View Public IPv4 address

Create VPC

  1. Return to the EC2 connection interface. To make sure you copy the aws-keypair.pem file to the EC2 Public server, we execute the command
ls

Create VPC

  1. Update the permissions for the aws-keypair.pem file by running the chmod 400 aws-keypair.pem command. AWS requires a key pair file that needs to be restricted before it can be used to connect to the EC2 server.
chmod 400 aws-keypair.pem

Create VPC

  1. SSH to EC2 Private server
ssh -i aws-keypair.pem ec2-user@<EC2 Private server's private IP address>

Create VPC

  1. Perform ping test to amazon.com. As you can see, we are not able to connect internet from EC2 Private. In the next step, we will create NAT Gateway to allow the EC2 Private server to connect to the internet in the outbound direction. Keep the connection to EC2 Private so we can check the connection to internet after completing the creation and configuration of NAT Gateway.
ping amazon.com

Create VPC