In this article, we will guide you through setting up a personal VPN server and connecting to it from Android and iOS devices. The process is simple: it takes only 10-15 minutes and doesn’t require any server administration expertise. Follow the steps below and you’ll have a personal VPN up and running in just a few minutes.
A personal VPN server ensures your data privacy and security when using Instagram or other online services. In this tutorial, we’ll deploy a Gcore VDS as a server for the VPN. This is a cheap virtual server suitable for hosting simple and low-demand applications, such as a VPN.
Public VPN servers may seem like a cost-effective solution for securing your internet connection. However, they often come with several limitations:
Now that you’re familiar with the benefits of a private VPN server, let’s dive into ordering and setting it up.
First, you need to order a server with a Linux-based operating system, Ubuntu 18.04.
Use the parameters shown in Figure 1.
Note that the data center closest to your location is the better choice in terms of latency. However, some of the Gcore locations are cheaper than others, and the closest data center may not be the cheapest.
If you don’t have a Gcore Hosting account yet, you will see the registration form to sign up. Go ahead and create your account. Then, find your server order in the Hosting control panel > Products/Services > Virtual private servers.
On the order page (see Figure 3), you can leave default values in all the fields. Just make sure you’ve chosen Ubuntu 18.04.
Click Add to cart and then buy the server using a method that is most convenient for you: a bank card, PayPal, or other. After the payment, your server will be automatically activated. This takes up to twenty minutes.
To connect to the server remotely via SSH, you need to use a terminal on your local machine. Here’s how:
ssh [username]@[server IP]
For example, if the instructions show “server IP address: 185.14.67.190” and “user: root”, then the command will be:
Welcome to Ubuntu 18.04.6 LTS (GNU/Linux 4.15.0-208-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage * Introducing Expanded Security Maintenance for Applications. Receive updates to over 25,000 software packages with your Ubuntu Pro subscription. Free for personal use. https://ubuntu.com/pro Last login: Wed Mar 29 13:49:22 2023 root@joan:~#
That means the connection is established, and you can manage the virtual server.
First, you need to set your VPN server’s username and password. These will be used to access and connect to the VPN server after the configuration process (Step 4) is complete. Note that this is not the same as your root password for the Ubuntu server; here you have to create your own username and password.
Make sure your username and password don’t have any special symbols such as ‘*’, ‘$’, ‘#’, ‘^’, etc. Use only letters (AbcDef, etc.) and numbers (01234, etc.). For your password, we recommend using at least twelve symbols to make it stronger and more secure.
For example:
echo 'MY_USERNAME=myvpn' | sudo tee -a ~/.bashrc
echo 'MY_PASSWORD=sdsbUInns40x' | sudo tee -a ~/.bashrc
Here the username is myvpn and the password is sdsbUInns40x.
If you’re not familiar with setting up a VPN server or using the Linux shell, we recommend pressing the “Enter” button on your keyboard after entering each command. This will ensure that the commands are executed properly.
sudo apt-get update && sudo apt-get upgrade -y
Use the following command to install both:
sudo apt install strongswan strongswan-pki -y
mkdir -p ~/pki/{cacerts,certs,private}
chmod 700 ~/pki
echo 'INTERFACE_NAME="ens3"' | sudo tee -a ~/.bashrc echo "VPN_IP_ADDRESS=$(ip addr show dev "$INTERFACE_NAME" | awk '$1 == "inet" {gsub(/\/.*$/, "", $2); print $2}')" | sudo tee -a ~/.bashrc source ~/.bashrc
ipsec pki --gen --type rsa --size 4096 --outform pem > ~/pki/private/ca-key.pem
ipsec pki --self --ca --lifetime 3650 --in ~/pki/private/ca-key.pem \ --type rsa --dn "CN=VPN root CA" --outform pem > ~/pki/cacerts/vpn-cert-ca.pem
This certificate will be valid for 10 years.
ipsec pki --gen --type rsa --size 4096 --outform pem > ~/pki/private/server-key.pem
ipsec pki --pub --in ~/pki/private/server-key.pem --type rsa | ipsec pki --issue --lifetime 1825 \ --cacert ~/pki/cacerts/vpn-cert-ca.pem \ --cakey ~/pki/private/ca-key.pem \ --dn "CN=$VPN_IP_ADDRESS" --san "$VPN_IP_ADDRESS" \ --flag serverAuth --flag ikeIntermediate --outform pem > ~/pki/certs/server-cert.pem
This certificate will be valid for 5 years.
sudo cp -r ~/pki/* /etc/ipsec.d/
sudo mv /etc/ipsec.conf{,.original}
echo "config setup charondebug="ike 1, knl 1, cfg 0" uniqueids=no conn ikev2-vpn auto=add compress=no type=tunnel keyexchange=ikev2 fragmentation=yes forceencaps=yes dpdaction=clear dpddelay=300s rekey=no left=%any leftid=$VPN_IP_ADDRESS leftcert=server-cert.pem leftsendcert=always leftsubnet=0.0.0.0/0 right=%any rightid=%any rightauth=eap-mschapv2 rightsourceip=10.123.45.0/24 rightdns=95.85.95.85,2.56.220.2 rightsendcert=never eap_identity=%identity" > /etc/ipsec.conf
echo ": RSA "server-key.pem" $MY_USERNAME : EAP "$MY_PASSWORD" " > /etc/ipsec.secrets
sudo ufw enable
sudo ufw allow OpenSSH
sudo ufw allow 500,4500/udp
sed -i "\|^#\s*ufw-before-forward$|a\\ *nat\\ -A POSTROUTING -s 10.123.45.0/24 -o $INTERFACE_NAME -m policy --pol ipsec --dir out -j ACCEPT\n\ -A POSTROUTING -s 10.123.45.0/24 -o $INTERFACE_NAME -j MASQUERADE\n\ COMMIT\n\ \n\ *mangle\n\ -A FORWARD --match policy --pol ipsec --dir in -s 10.123.45.0/24 -o $INTERFACE_NAME -p tcp -m tcp --tcp-flags SYN,RST SYN -m tcpmss --mss 1361:1536 -j TCPMSS --set-mss 1360\n\ COMMIT" /etc/ufw/before.rules
sed -i "\|^#\s*End\srequired\slines$|a\\ -A ufw-before-forward --match policy --pol ipsec --dir in --proto esp -s 10.123.45.0/24 -j ACCEPT\\ -A ufw-before-forward --match policy --pol ipsec --dir out --proto esp -d 10.123.45.0/24 -j ACCEPT" /etc/ufw/before.rules
echo "net/ipv4/conf/all/send_redirects=0 net/ipv4/ip_no_pmtu_disc=1 net/ipv4/ip_forward=1 net/ipv4/conf/all/accept_redirects=0" >> /etc/ufw/sysctl.conf
sudo ufw disable
sudo ufw enable
sudo systemctl stop strongswan
sudo systemctl start strongswan
The root CA certificate is very important to enable the VPN service. You need to copy it to the device from which you want to connect to the server.
cat ~/pki/cacerts/vpn-cert-ca.pem
The output will show you something similar to this:
-----BEGIN CERTIFICATE----- # We’ll skip the rest of the content for brevity -----END CERTIFICATE-----
Congratulations! Your private VPN server is set up.
The way that you connect to a private VPN server depends on the type of platform you’re using. We’ll show you how to do it from Android and iOS.
Tap Import certificate.
Congratulations! You’ve connected to your private VPN server.
Congratulations! You’ve connected to your private VPN server.
In this tutorial, we explained how to set up a private VPN server using Gcore VDS. Now you can securely access Instagram and other online services from anywhere, without the limitations of public VPN servers.
Check out our article dedicated to setting up your personal VPN server using a preconfigured Gcore Cloud OpenVPN instance: How to Run OpenVPN on Ubuntu Server.