Hello, here is an example of how to build your own VPN server using a VPS server. Currently, I am using OVH to get a VPS. I have been using this exact VPS for email for over three years now. So, I have just expanded it to also control VPN for my entire network. Why, well I wanted full network control. This allows my VPN to control my nework access point and that is globally. I will always appear to be reaching the net from that on ip no matter where in the world I am. I may add more servers in the future for content restricted access but for now. This is all a proof of concept.
Setup the Server Side
Prerequisites
- VPS Provider: A small VPS (e.g., 1GB RAM) from providers like DigitalOcean, Vultr, Linode, or OVH.
- Operating System: Ubuntu 22.04 or 24.04 LTS is recommended.
- SSH Client: Terminal (macOS/Linux) or PuTTY (Windows).
- Log in to your VPS: Connect as root using SSH:
ssh root@vps_ip_address. - Update your System: Run the following commands to ensure your server is updated:bash
apt update && apt upgrade -y - Run the Installation Script: Use the popular, open-source script by Nyr:
- bash
wget https://git.io/vpn -O openvpn-install.sh && bash openvpn-install.sh - Configure the VPN: The script will ask for protocol (UDP is recommended), port (default is fine), and DNS settings. Press enter to accept defaults.
- Create a Client: Once installed, the script asks to add a new client (e.g., “phone” or “laptop”).
- Download the Configuration File: The script creates a
.ovpnfile (e.g.,client.ovpn). Use an FTP client like FileZilla to download this file from your VPS to your computer. - Connect: Install the OpenVPN Connect client on your device, import the
.ovpnfile, and connect.
Setup the Client Side OpnSense
Phase 1: OpenVPN Client Instance Setup
- Create Instance: Navigate to VPN > OpenVPN > Instances and click + to add a new instance.
- Configuration: Enable ‘Advanced Mode’. Set the role to Client. Enter the server address, port, and protocol (UDP/TCP) from your provider’s configuration file.
- Authentication: Choose the appropriate Certificate Authority (CA) and client certificate. Enter your VPN provider’s username and password.
- Prevent Local Routing Conflicts: Under “Miscellaneous Options,” select root no pull to prevent the VPN server from hijacking your default gateway before you are ready.
- Save and apply changes.
Phase 2: Interface and Gateway Configuration
- Assign Interface: Go to Interfaces > Assignments. Assign the new OpenVPN instance (e.g.,
ovpnc1) to a new interface (e.g.,VPN_CLIENT). - Enable Interface: Click on the new interface, check Enable Interface, and save.
- Gateway Check: Navigate to System > Gateways > Single to ensure a gateway was created for the VPN.
OPNsense Forum +4
Phase 3: Outbound NAT
- Navigate to Firewall > NAT > Outbound.
- Set Mode to Hybrid outbound NAT rule generation and Save.
- Add a new rule:
- Interface:
VPN_CLIENT(the interface created in Phase 2) - Source Address:
LAN net - Translation / Target:
Interface Address
- Interface:
- Save and Apply.
Phase 4: Firewall Rules (Route Traffic)
Save and Apply.
Go to Firewall > Rules > LAN.
Add a new rule to the top:
Action: Pass
Interface: LAN
Protocol: Any
Source: LAN net
Destination: Any
Gateway: Select the OpenVPN Gateway created in Phase 2.
