How to set up your own VPN server in under 5 mins
Several companies provide VPN services for both free and for a fee however, there is no guarantee that your data would be secure if you use a free VPN service, companies could be logging and selling data for profit. Let us see how to easily set up our own wireguard VPN server in the cloud in under 5 minutes using the setup script which you can check out at GitHub.
- Cloud VM instance running Ubuntu 20.04
- Open UDP port 51820
Installation steps
- Login to the ubuntu VM instance
- Run the following command to update the apt cache and upgrade all packages to the latest version
sudo apt update -y && sudo apt upgrade -y
3. Run the command to download and save the script as wireguard.sh
wget https://bit.ly/wireguard-script -O wireguard.sh
4. Run the command to run the script that will setup the wireguard server
bash wireguad.sh <number of clients>
<number of clients> is the max number of clients you wish the server should support, the default value is 1
The example below for 3 clients
bash wireguad.sh 3
Will generate client configuration files client1.conf, client2.conf and client3.conf.
If the script fails to auto-detect the network interface name and throws an error run the script with your server’s network interface name as the second argument along with the number of clients usually it will be eth0 or ens1.
Adding Additional clients later
To add more clients after setting up the VPN server run the following commands
wget https://bit.ly/wireguard-add -O add_clients.shbash add_clients.sh <number of clients>
<number of clients> default value is 1
This will stop the VPN server for a minute and add the additional number of clients and will generate configs for the new clients.
bash add_clients.sh 2
Will generate 2 more clients and generate client4.conf and clinet5.conf config files.
Connect Client to server
for connecting the clients to the server steps vary according to the operating system of the clients
Connecting windows client
Download and install the windows client from the official wireguard website
open it and load the client configuration file (client.conf) we made in above step by clicking add tunnel and selecting the file
Click on Activate and you are connected to the VPN.
Connecting Android client
Install the official wireguard application form Play Store, load the configuration and connect to the VPN.
Connecting IOS client
Install the official wireguard application from App Store, load the configuration and connect to the VPN.
Connecting Mac OS Client
Install the official wireguard application from App Store, load the configuration and connect to the VPN
Connecting a Linux Client
For Linux, you can follow the installation instruction details for your specific distribution from the official wireguard website, after installing wireguard
copy the client configuration file (preferably rename it wg0.conf)
/etc/wireguard/ directory and run (only tested for Ubuntu directory location may vary according to distributions please verify if using other distributions)wg-quick up wg0
Conclusion
That is it you have successfully set up your own VPN and connected to it one last thing verify your IP address after connecting to the VPN for that simply do a Google search if everything is correct the IP address shown will be the public IP address of your VM instance.
Liked my work? Buy me a coffee