Deploying a Secure Home VPN with OpenVPN on Raspberry Pi
For users who prefer the robust, widely-supported protocol of OpenVPN, setting up a private home VPN on a Raspberry Pi remains a highly effective solution. This guide walks you through the installation using PiVPN and provides specific instructions for accessing the configuration files and deploying them on popular travel routers like the GL.iNet Mango (GL-MT300N-V2) or Opal (GL-SFT1200).
Prerequisites
- A Raspberry Pi (3B+ or newer recommended), running Raspberry Pi OS Lite.
- SSH access to the Pi.
- Access to your router’s administrative settings for port forwarding.
- A GL.iNet travel router (Mango or Opal) to serve as the remote client.
- A Dynamic DNS (DDNS) hostname configured if you do not have a static public IP address. (See my previous post: How to Set Up No-IP Service for Your Home Network.
Step 1: System Preparation and Static Local IP
Ensure your Pi is up to date and has a permanent local IP address. This static address tells your main router where to direct incoming VPN connections.
- Update Your System: Log into your Pi and execute:
- Set a Static Local IP Address: Configure your Pi to use a fixed IP address outside your router's default DHCP range (e.g., use 192.168.1.50 if your router uses 192.168.1.100-200 for DHCP).
sudo apt update
sudo apt full-upgrade -y
Step 2: Install and Configure PiVPN (OpenVPN)
We use PiVPN to automate the creation of the OpenVPN server, including certificates and encryption settings.
- Execute the Installation Script:
- Follow the Dialogue Prompts:
- Confirm the static IP address set in Step 1.
- Select VPN Protocol: Choose
OpenVPN
when prompted. - Select Port: Use the standard OpenVPN port,
1194
(UDP), unless you need to change it. - Public IP or DNS: Input your DDNS hostname (e.g.,
myhomevpn.ddns.net
) or choose 'Public IP' if you have a static address. - DNS Provider: Choose your preferred public DNS service (e.g., Cloudflare or Google).
- Security: The installer will generate the server certificates.
- You will be prompted to reboot. Confirm to reboot.
curl -L [https://install.pivpn.io](https://install.pivpn.io) | bash
Step 3: Configure Router Port Forwarding
You must instruct your home router to forward external VPN requests (on port 1194 UDP) to your Raspberry Pi’s internal static IP address.
- Log into your router’s web interface.
- Navigate to the "Port Forwarding" or "NAT" settings.
- Create a new forwarding rule:
- External Port:
1194
- Internal Port:
1194
- Internal IP Address: The static IP of your Raspberry Pi (e.g.,
192.168.1.50
) - Protocol: Set this to
UDP
.
- External Port:
- Save and apply the settings.
Step 4: Generate OpenVPN Client Profiles
Create the .ovpn
configuration file needed for your GL.iNet router client and any other devices (phones, tablets, laptops) that will connect.
- Add a Client: Log back into your Pi via SSH (after the reboot) and run:
- Enter a descriptive name for the client (e.g.,
glinet_opal
orjoes_iphone
). - The
.ovpn
configuration file will be generated and saved in the/home/pi/ovpns
directory. - We will now set up a network share to easily retrieve this file.
pivpn add
Step 5: Setup Network Share (Samba) to Access Files
To easily transfer the .ovpn
file to your computer and then into cloud storage (OneDrive, Dropbox, iCloud) for sharing, we will set up a Samba share on the Pi.
- Install Samba:
- Set Samba Password: Set a password for the 'pi' user to access the share:
- Configure Samba Share: Edit the Samba configuration file:
- Scroll to the very bottom of the file and add the following section to share the OpenVPN configuration folder:
- Save the file (Ctrl+O, then Enter) and exit the editor (Ctrl+X).
- Restart Samba Service:
- Retrieve the Configuration File: Access the share from your computer using your network file explorer (e.g., Finder on Mac, File Explorer on Windows) via the Pi’s static IP (e.g.,
\\192.168.1.50
orsmb://192.168.1.50
). Copy the[clientname].ovpn
file and move it into your desired cloud folder (OneDrive, Dropbox, etc.).
sudo apt install samba samba-common-bin -y
sudo smbpasswd -a pi
(Enter a secure password, different from your system password if desired.)
sudo nano /etc/samba/smb.conf
[OpenVPN_Configs]
path = /home/pi/ovpns
writeable = yes
browseable = yes
valid users = pi
sudo systemctl restart smbd
Step 6: Configure Mobile, Tablet, and PC Clients
The .ovpn
configuration file retrieved in Step 5 is used by OpenVPN client applications on virtually any operating system to establish the connection. Official OpenVPN apps are available for all major platforms, including phones, tablets, laptops, and personal computers.
- Install the OpenVPN Client App: Download and install the official or recommended OpenVPN client application for your specific device (iOS, Android, Windows, macOS, Linux).
- Import the Profile:
- Transfer File: Use the cloud service (OneDrive, Dropbox, etc.) or a direct connection to transfer the
[clientname].ovpn
file to the device you wish to connect. - Import: Open the OpenVPN client app and select the option to "Import Profile" or "Import File." Choose the
.ovpn
file you just transferred.
- Transfer File: Use the cloud service (OneDrive, Dropbox, etc.) or a direct connection to transfer the
- Connect: Once imported, activate the connection toggle or button within the OpenVPN app to establish the secure tunnel to your home network.
Step 7: Configure the GL.iNet Router (Client)
Finally, deploy the OpenVPN configuration onto your GL.iNet travel router (Mango or Opal).
- Access Router Interface: Connect to the GL.iNet router (via Ethernet or WiFi) and open its web management panel (usually
http://192.168.8.1
). - Navigate to VPN Settings: Go to the "VPN" section and select "OpenVPN Client."
- Upload Configuration: Click the option to import an OVPN file. Upload the
[clientname].ovpn
file you retrieved in Step 5. - Connect: Once the file is imported, click "Connect." Your GL.iNet router will now tunnel all its traffic (and the traffic of any device connected to it) back through your Raspberry Pi home VPN.