Setting up your own VPN server on a Raspberry Pi is a powerful way to protect your privacy, secure your internet connection, and access your home network from anywhere in the world.
Whether you're a digital nomad, privacy enthusiast, or just want to learn something new, this guide will walk you through how to set up a VPN server on a Raspberry Pi—even if you're a complete beginner.
Why Set Up a VPN Server on Raspberry Pi?
Here are a few key benefits of hosting your own VPN server at home:
- Secure your connection on public Wi-Fi networks (coffee shops, airports, etc.)
- Access home devices like security cameras or NAS remotely
- Bypass geographic restrictions when abroad
- Avoid data logging by third-party VPN providers
- Learn and explore networking and Linux fundamentals
What You’ll Need
- A Raspberry Pi (Pi 3, 4, or newer recommended)
- A microSD card (at least 8 GB, with Raspberry Pi OS installed)
- Internet connection with router access
- A public IP or dynamic DNS service (e.g., No-IP)
- SSH access or a monitor + keyboard connected to your Pi
Tip: Use Raspberry Pi Imager to quickly install Raspberry Pi OS.
Step-by-Step VPN Server Setup on Raspberry Pi
We’ll use PiVPN, a simple installer that supports OpenVPN and WireGuard (modern, fast VPN protocol).
Step 1: Update Your Raspberry Pi
Open the terminal or SSH into your Pi and run:
sudo apt update && sudo apt upgrade -y
This ensures you have the latest software and security patches.
Step 2: Install PiVPN
Now run the official PiVPN installation script:
curl -L https://install.pivpn.io | bash
The installer will guide you through a series of steps. You can choose between:
- WireGuard (Recommended): Faster and modern
- OpenVPN: More widely supported
For most users, WireGuard is easier and faster, especially on Raspberry Pi 4+.
Step 3: Configure the VPN Settings
During installation:
- Choose static IP (PiVPN can set this automatically)
- Choose the user account (usually `pi`)
- Select WireGuard or OpenVPN
- Open the suggested port on your router (defaults: WireGuard = 51820, OpenVPN = 1194)
You'll be prompted to enable unattended upgrades (recommended).
Step 4: Set Up Port Forwarding on Your Router
Login to your router’s admin page (usually `192.168.0.1` or `192.168.1.1`) and forward the selected port to your Raspberry Pi’s IP address.
For example:
- Service: WireGuard VPN
- Port: 51820 (UDP)
- Internal IP: `192.168.1.100` (your Pi)
Without port forwarding, external devices can’t reach your VPN server.
Step 5: Generate VPN User Profiles
Create a VPN profile (client) with this command:
pivpn add
You’ll be asked to name the client (e.g., `myphone`) and set a password.
Your config file will be saved in `/home/pi/configs/` (or similar directory). You can export it with:
pivpn -qr
This generates a QR code you can scan with a mobile VPN app like WireGuard app.
Step 6: Connect Your Devices
On Mobile (iOS or Android):
- Install WireGuard app
- Tap “+” → “Scan from QR code”
- Scan the QR from `pivpn -qr`
- Toggle the switch to connect
On Desktop (Windows/macOS/Linux):
- Install the WireGuard desktop client
- Import the `.conf` file
- Click “Activate” to connect
Optional: Use Dynamic DNS (DDNS)
If your ISP gives you a dynamic IP, you’ll need a DDNS like No-IP or DuckDNS.
How to Set It Up:
- Register an account and get a hostname (e.g., `mypivpn.no-ip.org`)
- Install the DDNS client on your Raspberry Pi
- Update your VPN config to use your DDNS hostname
VPN Server Performance on Raspberry Pi
Here’s a quick performance benchmark by model:
Raspberry Pi Model | WireGuard Speeds | Best For |
---|---|---|
Pi 3 B+ | ~30 Mbps | Basic browsing |
Pi 4 (4GB) | ~90–120 Mbps | HD streaming, remote access |
Pi 5 | 150+ Mbps | Power users, media servers |
Tip: For faster speeds, use Ethernet instead of Wi-Fi.
Security Tips for Raspberry Pi VPN
- Change default password: `passwd`
- Use strong passwords for VPN profiles
- Keep system updated: `sudo apt update && sudo apt upgrade`
- Disable SSH password login and use SSH keys instead
- Consider installing a firewall like `ufw` (Uncomplicated Firewall)
FAQ
Q: Is it safe to host a VPN on Raspberry Pi at home?
A: Yes, if you secure your system, change default passwords, and keep software updated. It’s much safer than using public VPNs with questionable privacy policies.
Q: Can I use this VPN on multiple devices?
A: Absolutely. You can create multiple client profiles with `pivpn add` for each device.
Q: What if my IP changes regularly?
A: Use a dynamic DNS service like DuckDNS or No-IP to keep a consistent address.
Q: Can I switch between WireGuard and OpenVPN?
A: Yes, but you’ll need to re-run the PiVPN installer to switch protocols.
Q: Do I need to keep Raspberry Pi on 24/7?
A: Yes, the Pi must stay online for the VPN to work when you're away from home.
Conclusion
Setting up a VPN server on your Raspberry Pi is one of the most rewarding DIY tech projects. It’s secure, cost-effective, and gives you total control over your online privacy.
With tools like PiVPN