Set Up VPN Server And VPN Router

This blog summarizes how to set up a VPN server and a VPN router.

Set Up VPN Server

Deploy an ubuntu 22.04 server on your target network. Run the following commands to install vpn server on it.

wget https://raw.githubusercontent.com/Angristan/openvpn-install/master/openvpn-install.sh -O ubuntu-22.04-lts-vpn-server.sh
chmod -v +x ubuntu-22.04-lts-vpn-server.sh
sudo ./ubuntu-22.04-lts-vpn-server.sh

Once it is done, an ovpn file will be generated, for example,

The configuration file has been written to /home/ubuntu/linux.ovpn.

Set Up VPN Router

Step 1: Install An Physical Ubuntu Server

Install ubuntu on a device which has:

  • A physical ethernet port connected to your home router. This port will be used to exchange data from and to the Internet.
  • A wifi adapter. This port will be used as a hotspot for your devices to connect. Any device connected to this hotspot will be able use send traffic through the vpn server.

This ubuntu server will be used as your VPN router.

Step 2: Set Up DNS

Run the following command to set up your DNS on your VPN router.

echo "[Resolve]
DNS=8.8.8.8 8.8.4.4
" | sudo tee /etc/systemd/resolved.conf.d/99-dns.conf

Restart your VPN router,

Step 3: Create A Wifi Hotspot

Run the following command to create a wifi hotspot.

sudo nmcli d wifi hotspot ifname {interface-name} ssid {wifi-ssid} password {wifi-passwd}

Step 4: Connect To Your VPN Server From Your VPN Router

Copy the opvn config file from your VPN server to your VPN router, and run the following command.

sudo openvpn --config {ovpn-config-file}

Step 5: Enable NAT On Ubuntu Server

iptables -t nat -A POSTROUTING -j MASQUERADE

This config will go away if you reboot your linux server. To make it persistent, do the following

sudo apt update -y && sudo apt install iptables-persistent

Now your VPN router is ready to use.