DEV Community

Subash for AWS Community Builders

Posted on • Originally published at Medium

CONFIGURE VPN TO ACCESS INSTANCES IN THE PRIVATE NETWORK

Launching EC2 and installing OpenVPN

  1. Launch an EC2 instance(public) in a VPC to setup openVPN(Ubuntu is taken in this lab)
  2. Connect to the EC2 instance through SSH then update and upgrade the instance using: sudo apt update sudo apt upgrade
  3. Install openVPN server in the public subnet and run the OpenVPN installer wizard using following commands: wget https://git.io/vpn -O openvpn-ubuntu-install.sh chmod -v +x openvpn-ubuntu-install.sh sudo ./openvpn-ubuntu-install.sh
  4. In the wizard, provide choices as shown in fig. Then, provide a client nameInstallation Wizard
  5. Check the status of openVPN server: sudo systemctl status openvpn-server@server.service If a restart is needed: sudo systemctl restart openvpn-server@server.service OpenVPN service status
  6. Download the .ovpn file to local pc. It is required to connect through openVPN desktop client. The name of the .ovpn file depends on the name of the client provided during the previous wizard installation. ssh -i "your-key.pem" ubuntu@<public ip address> "sudo -S cat /home/ubuntu/client_name.ovpn" > client_name.ovpn The directory for the .ovpn file could differ : /root/openVPN profile download

Configuring Security groups

The default port 1194 was selected in the wizard previously. So, the inbound rules should include Custom UDP for port 1194.
Inbound Rules

Downloading OpenVPN Connect and establishing the connection

  1. Go to https://openvpn.net/client-connect-vpn-for-windows/ (Windows)
  2. After the installation is completed, run the application and import the .ovpn file. IOpenVPN Client Console
  3. The imported profile details is shown. VPN Profile
  4. If all the configurations are proper, the connection will be successful. OpenVPN connectuion

Verifying the connection to the instance in private subnet

  1. Once the openVPN connection is successful, we can verify whether the instances in the private subnet can be connected to or not.
  2. Launch an instance in a private subnet for the same VPC as of the instance in the public subnet. EC2 console
  3. Take the private IPv4 address and PEM file and connect through SSH ssh -i "<pem-file>" ubuntu@<private-ip> EC2 ssh connection

Top comments (0)