FREE VPN with AWS
Tags: aws, vpn, devops, security
Published: 2022-09-27 07:00:58

#So,
You Want a Free VPN for securing you're connection, you don't want the third party to sneak up behind you and see or steal your data, you are not alone, we all want that, easy way buy a premium vpn there are tons of out there, but we they are paid, so lets have our **own VPN**.

Without Further Delay lets get started,

## PREQUISTE
 > AWS ACCOUNT
 > LITTLE BIT OF LINUX

We are going to use the service name **LightSail** in here, you ask why? Well, first we can run the sever for **free** (3 Months) if you are well-passed you're free tier of AWS.

Lets go to LightSail Console
![First thing you see why you go to LightSail](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pgzjfpin9567zexbg3km.png)

Let's create the Instance

![Instance Create](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lcmha4fal3puravlr1og.png)
We can use any OS amazon-linux-2, ubuntu we just needs to know the package name for the same, here I'm going with ubuntu:20.04LTS

Choose the Plan According to you're needs and select it 
![Plan](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/inm3wg1zxadkbfq62z0z.png)

While waiting for the instance to provision for you lets go to **Network** tab and create a **static-IP** for our VPN
![static-ip](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5ngataj4hwm6g7u83p5u.png)

Name the IP with anything, choose the Instance in which you want to attach the static-IP 
![static-ip](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ee2bge09nvig0k7dy628.png)

Let's connect to the instance with SSH, LightSail give us web-based ssh and terminal based, for terminal based we need the **key**, Download the Default key from here
![ssh key](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zjlrd8x5xdas9nxthhmd.png)
and lets start executing some linux commands.

## PART II
Start the SSH connection 
```
ssh ubuntu@<IP> -i <path-to-key>
```
Install the Wireguard
```
sudo -i
apt update 
apt install wireguard -y
```
![Installation of Wireguard](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yueab8z9q1txdt4ywh1n.png)

After Installing it, we need to enable the port forwarding so that after connecting to instance we can still use the internet freely
run the following command to do so
```
vim /etc/sysctl.d/10-wireguard.conf
```
and add the following line 
```
net.ipv4.ip_forward=1
```
After adding the line execute the following command to make it permanent
```
sysctl -p /etc/sysctl.d/10-wireguard.conf
```
![port forwarding enable](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wxztv6p23kkwusj4sygd.png)

After enabling the Port Forwarding lets move to the Wireguard directory
```
cd /etc/wireguard
```

### NOTICE: Important We are generating key for the server make sure that you don't share any private key from here.

Execute the following commands
```
wg genkey | tee server.key | wg pubkey > server.pub
```
![Keys are generated here](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rnfdke37uwbj9xf79gxa.png)

wg & wg-quick is command-line tool for interacting with Wireguard.
We will be using these file in our next step.

##Now Let's create the configuration file,
for our VPN here whatever you want to name the configuration file you can name it and it will create a interface with the same name
but it must contain the **.conf**
```
vim vpn.conf
```
Add these line into it 

```
[Interface]
Address = 10.1.1.1/24
ListenPort = 51820
PrivateKey = <server.key>
PostUp = iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
```
Make sure you add the server.key content here the file we created earlier
![Added the Configuration to vpn.conf](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z96fsjanqfi4aprk68ac.png)

## Let's Enable the VPN
run the following command to start it
```
systemctl enable --now wg-quick@vpn
```
Verify it's running successfully 
```
systemctl status wg-quick@vpn
```
![Started the VPN](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n683rnkwvdsur6nxaxgv.png)

## PART III
So our VPN Server is now running but we need to give the access to user, for that we need to generate some more files using the wg but I love the GUI so after doing some digging I found this amazing dashboard thanks to the author I can do everything from Dashboard only

### Install the Dashboard
Here the [github link](https://github.com/donaldzou/WGDashboard) 
let's clone the repo

```
git clone -b v3.0.6 https://github.com/donaldzou/WGDashboard.git wgdashboard
```
change the directory & execute some commands
```
cd wgdashboard/src
chmod u+x wgd.sh
./wgd.sh install
chmod -R 755 /etc/wireguard
apt install python3-pip -y
pip3 install -r requirements.txt
./wgd.sh start
```
![Execution of the above commands](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ocu88oe7dphe1e86ot7s.png)
![Server started](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zclasgnznyst1ct2xed2.png)

Make Sure the port 10086 being used by running 
```
netstat -tnlp
```
![checking the port](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lupuh1lyo8g0j7nvh5pu.png)

And we are done here

## Back to LightSail
Let Open these port 
**51820 UDP
10086 TCP**
By going into the networking tab
![port allowing](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sokfr3xcyjycxghzremg.png)

## PART IV
###We are in the ENDGAME
Open the Dashboard by going to 
``
public-ip-of-instance:10086
``
In my case http://3.111.147.192:10086/
![Logging Screen](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mw2lrl1m76lsjyvqxiwb.png)

Default Creds
``
username: admin
password: admin
``
After logging in 
![Dashboard ](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/raqpozjsjy4dn10eh7ag.png)

Go to the Setting Page
![Setting Page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fyrwge8a0tgka3gnx9jk.png)
change the 
``
Peer Remote Endpoint (This will be change globally, and will be apply to all peer's QR code and configuration file.)
``
From anything like this
![ip](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/72plgrqu342g6jbiwcz2.png)
to You're Public IP of the Instance in my case **3.111.147.192**

And then Go to the Configuration Page
![Configuration Page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e9pqys17sarohygvmyhf.png)

Click on the Blue Add Button on the Lower Right
Add the Username and Download the File by clicking on the small green button.
![Added the User](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xzij6cx24qvkaxassggy.png)

Go to WireGuard Client And add the tunnel by importing the downloaded file and click 
**ACTIVATE**

If Everything is right you will be connected to the VPN check your IP to verify it.

![whatsmyIP](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5cpb2nmemblrcpjyhdnz.png)

## That's How We can have our own VPN

If any question plz feel free to ask in the comments