Create Your Own VPN server in AWS and Connect from PC and Smart phones

In this post, we will create our own vpn server and we will connect to our vpn server from pc and smart phones. I chose AWS to create server because AWS offers 1 year free usage. So, we wont pay anything during 1 year. Then, it will charge us but definitely I can say that free tier( t2.micro instance) is very cheap.

So, let’s begin. First login/signup to AWS console. If you have an account, enter your mail address and password then login.

Select EC2 services.

Select “Region” wherever you want in the top right corner. The “Launch Instance”

After you launch instance, Choose an AMI screen will pop-up. And select “Aws Marketplace” and type “openvpn”. Then select “Open VPN Access Server”

In “Choose an Instance Type”, select “General purpose- t2.micro”, then “next”

Then, in “Instance details” page, leave them as default and click “next” again.

In Storage page, select GP2 as volume type, then next again.

You can type which tag you want for your instance. I typed “MyVPN”.

Select “Create a new security group” for your VPN server in following page and click “Review and Launch” and in following page, again click “Launch”

It will ask you about Keypair to access your VPN server by sshing. Choose “Create a new Keypair” and type what you want for your keypair, then click “Download Key Pair” and select the location(i.e. Desktop) where you want to download Key pair.

Your instance is launched! Click “View Instances” to view your VPN instance

So, that is it!. We have running VPN server. Now, we will switch to terminal to install “openvpn server” software and create username/group for openvpn. Our vpn server ip is written under Description tab in “Public IP” field.

Open the terminal and ssh to our vpn server. I downloaded vpn.pem into “Desktop” . Then give only read permission, and run the ssh command with vpn.pem file.

chmod 400 ~/Desktop/vpn.pem
ssh -i ~/Desktop/vpn.pem openvpnas@35.156.22.202

When you access to vpn server, the operating system will ask you a lot of questions, you can leave all of them as default (Press the Enter). Don’t forget to enter “yes” at the beginning agreeement question.

Please enter ‘yes’ to indicate your agreement [no]: yes

Then finally, enter password for our “openvpn” user.

sudo passwd openvpn
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

Now, open the browser, and type “https://35.156.22.202” and click “HIDE ADVANCED” and click “Proceed to 35.126.22.202”

Then, enter your openvpn username and password which you specified in the terminal and select Login and click “Go”

We have to download Openvpn client to connect to our VPN server. Click client which operating system you have. As a mac user, I downloaded Mac version of Openvpn.

In this step, you can download and install openvpn client. This is the final step of installing openvpn in the Mac:

Now, we have to import our profiles to open vpn client from openvpn server.

Enter your hostname of the server, username and password. Then, openvpn profiles will be imported to our client.

Then, now connect to your vpn server and do same stuffs again at the above!

So, that is it!! We should now connect to our vpn server, right? No wayy.. If we check our pc’s public ip, we are still in our country..

So, one thing is left.. We have to route all our traffic to our vpn server, otherwise our pc’s ip will not change!. To do that, login to https://35.156.22.202/admin and enter openvpn username/password and click “Agree”

Enter to Vpn settings and click to “Yes” under Should client Internet traffic be routed through the VPN? part, and click “Have clients use the same DNS servers as the Access Server host” under DNS Settings part. Finally Click “Save” and “Update server” in the https://35.156.22.202/admin/vpn_settings

So, let’s check again our ip. So, yes! we are now in the Frankfurt/Germany.

If we want to enter to vpn via mobile, how will we do? It is very easy. Dowload the openvpn ios/android apps from market place. As a iphone user, I will show in the iphone.

Download openvpn from apple store : https://itunes.apple.com/tr/app/openvpn-connect/id590379981?mt=8

Then, we have to download our openvpn profile into desktop. Go into https://35.156.22.202/?src=login and download “Yourself (user-locked profile)” So, automatically “client.ovpn” file will be downloaded. Change its name to “vpn.ovpn”. Send this file to your mail address and open in your iphone mail.

To sum up, after these steps, you will finally connecto to your own vpn server securely from your pc and smart phones.