OpenVPN v/s Wireguard
Published: 2022-08-31 17:27:10

**A virtual private network extends a private network across a public network and enables users to send and receive data across shared or public networks. As the name suggest it virtually  connects our system to the private network.** 
One most important use of VPN can be transmitting sensitive information, which needs to be done via your office network, you can do it at your home by virtually getting into office network.
 
There are many VPNs available.
One of them is OpenVPN.

**OpenVPN is an open source Virtual Private Network (VPN). It creates secure connections over the Internet using a custom security protocol that utilizes SSL/TLS.**

Let's demonstrate it.

Step-1: Login to your AWS console>>Choose a region (Here I have chosen the Mumbai region)

Step-2: Go to VPC page>> Click on create VPC >> Click on VPC only >> Give a name to your VPC, give IPv4 CIDR range

Step-3: Create a Private subnet under it- For that search, subnet>>Click on create subnet>>Fill in the details (Choose above created VPC, give a Name, Availability zone, give CIDR range>>Click on create a subnet.

Step-4:Go to route table>>Click on create route>>Fill in the details(Give it name and choose VPC created on step-1)>>Click on create.

Step-5:Associate route table with the subnet- Select Route table -> Subnet Associations -> Edit Subnet Associations -> Select above created Subnet -> Save.

Step-6:Now launch a EC2 instance>>Go to EC2 instance>>Click on Launch an instance>>Fill in the details(Type: t2.micro,_**Do remember to disable public IP**_, Storage: Default, Tags – Name: give a name, Security: Give it according to your requirement, Keypair: your existing key pair or create new if you don’t have an existing keypair >> Launch instance.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ae2ic3swjeiodxx9f7cj.jpeg)

As this has no public IP address so we cannot access it directly. We can access it if any how we get into AWS network.

Step-7:Now launch a EC2 instance>>Go to EC2 instance>>Click on Launch an instance>>Search OpenVPN AMI>>Fill in the details(Type: t2.micro, Storage: Default, Tags – Name: give a name, Security: Give it according to your requirement, Keypair: your existing key pair or create new if you don’t have an existing keypair >> Launch instance.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ns8180zlu97gvj7xan2b.jpeg)

Step-8: Try to ping to the private server from your server-You will get no response


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gqagg6bq7q2gjkuc8z3e.jpeg)
Step-9:SSH into your openVPN server>>Keep on entering(go with default setting)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cctb5uk9jxk18blcsydg.jpeg)

Step-10:Save the admin and client url and then login as "openvpnas"

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1h56qj0usk9c4qqz51zk.jpeg)
Step-11: Now set password for your vpn- to set password give the command `sudo passwd openvpn`

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ttysg260m1kxhcm1d3wy.jpeg)
Step-12: Now open the OpenVPN application >>Create new connection>>
In url section give the client url that we saved>>click on next>>click on accept

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/euk290fpcnhus1gj2qyn.jpeg)
Step-13:Give username "openvpn" and password you have set in the server>>Click Import>>Click accept>>again confirm password>>Turn on the VPN

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kxhr5uvgo2p6slxstj8o.jpeg)
Step-14: Go back to the openvpn server>>Ping the private server now

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/apy6wagecnk4jg6c2tpx.jpeg)

Now Let's Demonstrate Wireguard VPN:

**WireGuard is an application that allows you to set up a secure virtual private network (VPN), known for its simplicity and ease of use. It uses proven cryptographic protocols and algorithms to protect data.**

Step1-6 to be repeated as above

Step-7:Now launch a EC2 instance>>Go to EC2 instance>>Click on Launch an instance>>Search for Linux based kernel AMI (here I have taken ubuntu)>>Fill in the details(Type: t2.micro, Storage: Default, Tags – Name: give a name, Security: Give it according to your requirement, Keypair: your existing key pair or create new if you don’t have an existing keypair >> Launch instance.
_NOTE: Wireguard is primarily designed for Linux based kernel_

Step-8: Since we need to reboot the server so let's allocate an Elastic IP to it. Search Elastic IP>>Click on associate Elastic IP address.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/38wirf8645zyfzkxadxg.jpeg)

Now click on actions>>Click on associate IP address

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e9iabhf1pxilxrxmwnd0.jpeg)
Now choose the public server's IP address:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/946z0ojnsqlokv6dchxr.jpeg)
Step-9:SSH into the public server that is created in step6.

Step-10:Now we need to install pivpn in order to configure wireguard in the server.

Go to root- `sudo su` -> `cd`
To install pivpn use- `curl -L https://install.pivpn.io | bash`

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b2zy18wv5qv11aecp8q7.jpeg)

Step11:Now pivpn will ask some configuration go on clicking ok(to go with default setting of pivpn)
Make sure you choose VPN as wireguard:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o3nzl08yvurqg9xxz97p.jpeg)
Keep the default port as it is:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w4vfqigebjrtjbde8m4i.jpeg)
Now, reboot the server-`sudo reboot now` 
Step-12: SSH again you will not be able to access the server as the security group has no access for the new wireguard port number.

Step-13: Go to Security group of the server>>Edit the inbound rule>> add custom udp and give port number 51820.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rwkltjq1dxk8sm896023.jpeg)
Step-14: Now ssh again.
Now give the command- `pivpn add`>>Give name for the client
Step-15: Now see the config file created.
To see the content of file give the command- `cat /home/ubuntu/configs/"yourclientname".conf`

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vakifnai5nqsapvgqs5w.jpeg)
Step-16:Copy the content of file>> create a key.conf file in notepad and paste and save it

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c6e1gxfglxq7l96goh5y.jpeg)
Step-17: go to aws and edit security group of private server and 
add inbound rule and allow _All traffic but source should be from vpn server security group_

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mbspxupc5iw3v8yywpib.jpeg)

Step-18: Now install wireguard and open it>> click on import tunnel from file and browse the key.conf file

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dxnckdc799w27u07p18o.jpeg)
Step-19: click on activate

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/32ubs2vu7j9p6wo0le33.jpeg)
Step-20: go to the public server and try to ping or ssh to the private server, you will be able to do so.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oujxlpn0ot9p5bqwcshf.jpeg)
Comparing Them:

- Wireguard is modern VPN tunneling (communication) protocol that uses UDP for transferring data.
OpenVPN is a tunneling protocol mainly used for VPNs, and it transfers data with either UDP or TCP. It is most widely used.

- Wireguard is much faster regarding uploading and downloading speed as compared to openVPN.

- In case of encryption both use the latest technology to encrypt the transmitted data. Both of them have good authentication technique.

- Wireguard's current version has just around 4000 lines of code, which is approximately five times less than the OpenVPN files code lines. OpenVPN has around 70,000 lines of code. This makes easier to find bugs in wireguard rather than openVPN

- A VPN protocol must be compatible with various operating systems and not too difficult to implement for it to be widely recognized and used. OpenVPN is easy to use and compatible with basically any operating system. For wireguard, at first linux version of the software was released and was incorporated into linux 5.6 kernels.
However, it's continuous development has made it cross-platform. It now supports in Windows, macOS, BSD, iOS, Android. 

However, both are secure open-source VPN protocols and can be implemented according to requirement.