Create your own VPN server to securely access your home network from anywhere in the world. Browse safely on public Wi-Fi, access files on your home network remotely, and bypass geo-restrictions—all without monthly subscription fees.
What You're Building
A personal VPN server that:
- Encrypts all your internet traffic
- Lets you access home network remotely
- Protects you on public Wi-Fi
- Appears as if you're browsing from home (bypass geo-blocks)
- Works on phone, laptop, tablet
- No monthly fees (unlike commercial VPNs)
- You control all your data
- Supports multiple devices and users
Difficulty: ⭐⭐ Easy Time Required: 1-2 hours Cost: $35-55 (one-time) Monthly Savings: $5-15 vs. commercial VPN
What You'll Need
Required Components
Raspberry Pi
- Raspberry Pi 4 – Best performance for multiple users
- Raspberry Pi 3 B+ – Great for 1-2 users
- Any Pi with ethernet works
Storage
- SanDisk 128GB microSD Card – Plenty of space
- Minimum 8GB
Network
- Ethernet cable (highly recommended)
- Reliable internet connection
- Router with port forwarding capability
Power
- Official Raspberry Pi power supply
- Stable power critical for 24/7 operation
Case
- Pi 4 Case – If using Pi 4
- Pi 3 B+ Clear Case – If using Pi 3 B+
- Good ventilation for always-on use
Optional but Recommended
UPS (Uninterruptible Power Supply)
- Small UPS – Keeps VPN running during power blips
- Prevents corruption from unexpected shutdowns
VPN Protocol Choice: WireGuard vs OpenVPN
We'll use WireGuard - it's newer, faster, and simpler than OpenVPN.
WireGuard: ✅ Faster speeds ✅ Better battery life on mobile ✅ Simpler configuration ✅ Modern cryptography ✅ Easier troubleshooting
OpenVPN:
- Older, more widely supported
- More configuration options
- Better for restrictive networks
- Still available if you prefer it
This guide uses WireGuard via PiVPN (makes setup easy).
How a VPN Works
Without VPN: Your Device → Internet → Website (Anyone on network can see your traffic)
With VPN: Your Device → Encrypted Tunnel → Your Home → Internet → Website (Traffic encrypted, appears to come from your home)
Use cases:
- Coffee shop Wi-Fi? Encrypted and safe
- Hotel network? Protected from snooping
- Traveling abroad? Access home services
- Avoid ISP tracking? Routes through your home
Step-by-Step Setup Guide
Step 1: Install Raspberry Pi OS
Using Raspberry Pi Imager:
- Download from raspberrypi.com/software
- Choose OS: Raspberry Pi OS Lite (64-bit)
- Configure settings (gear icon):
- Hostname:
vpn-server - Enable SSH
- Set username and password
- Configure Wi-Fi (but use ethernet!)
- Set locale
- Hostname:
- Write to SD card
Step 2: Boot and Initial Setup
- Insert SD card in Pi
- Connect ethernet cable
- Power on Pi
- Find Pi's IP address (check router or use
ssh vpn-server.local)
SSH into Pi:
ssh username@vpn-server.local
# or
ssh username@192.168.1.50
Update system:
sudo apt update
sudo apt upgrade -y
Step 3: Install PiVPN
PiVPN is an automated installer that handles everything.
Run installer:
curl -L https://install.pivpn.io | bash
Installation wizard:
- Welcome screen → OK
- Static IP warning → OK (we'll configure this)
- Static IP configuration:
- Choose interface (eth0 for ethernet)
- Note current IP (e.g., 192.168.1.50)
- Set as static: Yes
- User selection → Choose your username
- Protocol choice → WireGuard (recommended)
- Default WireGuard port → 51820 (keep default)
- DNS provider:
- Cloudflare (fast, privacy-focused) ← Recommended
- Google (fast, logs data)
- OpenDNS (reliable)
- Pi-hole (if you have one running)
- Public IP or DNS:
- Use your public IP (if static)
- OR use Dynamic DNS service (if IP changes)
- Enable unattended upgrades → Yes (security updates)
- Installation completes → Reboot: Yes
Wait 2-3 minutes for installation and reboot.
Step 4: Set Up Static IP on Router
Your Pi needs a consistent local IP address.
Option 1: DHCP Reservation (Recommended)
- Log into your router admin panel
- Find DHCP settings or LAN settings
- Locate your Pi in connected devices
- Reserve/assign static IP (e.g., 192.168.1.50)
- Save settings
Option 2: Configure on Pi (if router doesn't support it)
- Already done during PiVPN installation
- Pi will use same IP every time
Step 5: Port Forwarding
Critical step! Your router must forward VPN traffic to your Pi.
Configure port forwarding on router:
- Log into router admin panel
- Find "Port Forwarding" or "Virtual Server" settings
- Create new rule:
- Service/Name: WireGuard or VPN
- Protocol: UDP
- External Port: 51820
- Internal IP: Your Pi's IP (192.168.1.50)
- Internal Port: 51820
- Save and apply settings
Test port is open (from external network):
- Visit: canyouseeme.org
- Enter port 51820
- Should show "Success" (may need to create client first)
Step 6: Get Your Public IP Address
Find your home's public IP:
curl ifconfig.me
Example: 203.0.113.45
If your IP changes (dynamic IP):
- Set up Dynamic DNS (DDNS)
- Free services: No-IP, DuckDNS, Dynu
- Update PiVPN config with DDNS hostname
Step 7: Create VPN Client
Create client for your device:
pivpn add
Follow prompts:
- Enter name for this client (e.g., "iphone", "laptop")
- Enter valid number of days (default 1080 is ~3 years)
- QR code displays (for mobile devices)
Output:
- QR code for mobile scanning
- Config file saved:
/home/username/configs/clientname.conf
Create multiple clients:
pivpn add
# Repeat for each device
Step 8: Install Client Apps
Mobile (iPhone/Android):
- Install "WireGuard" app from App Store/Play Store
- Open app → Add Tunnel → Scan QR code
- Scan QR code displayed during
pivpn add - Toggle on to connect
Computer (Windows/Mac/Linux):
- Download WireGuard client from wireguard.com/install
- Install application
- Transfer config file from Pi to computer:
# On your computer scp username@192.168.1.50:~/configs/laptop.conf ~/Downloads/ - Open WireGuard app → Import tunnel from file
- Select the .conf file
- Activate tunnel
Step 9: Test VPN Connection
From mobile/computer:
- Connect to cellular data or different network (NOT your home Wi-Fi)
- Enable VPN in WireGuard app
- Should connect within 1-2 seconds
- Visit: whatismyip.com
- Should show your HOME IP address, not your current location
Test DNS:
nslookup google.com
Should use the DNS provider you selected during setup.
Test local network access:
- Try accessing local network devices
- Example: http://192.168.1.1 (router admin)
PiVPN Management Commands
Useful commands:
# Add new client
pivpn add
# List all clients
pivpn list
pivpn -c # Show connected clients
# Remove client
pivpn remove
# Regenerate QR code
pivpn -qr clientname
# Show stats
pivpn -d
# Backup configs
pivpn backup
# Update PiVPN
pivpn update
# Debug issues
pivpn debug
Dynamic DNS Setup (If Your IP Changes)
If you don't have static IP from ISP:
Option 1: DuckDNS (Free, Easy)
- Create account: duckdns.org
- Create subdomain:
yourhome.duckdns.org - Get token from dashboard
- Install DuckDNS on Pi:
mkdir ~/duckdns
cd ~/duckdns
nano duck.sh
Add:
echo url="https://www.duckdns.org/update?domains=yourhome&token=YOUR_TOKEN&ip=" | curl -k -o ~/duckdns/duck.log -K -
Make executable and schedule:
chmod 700 duck.sh
crontab -e
Add line:
*/5 * * * * ~/duckdns/duck.sh >/dev/null 2>&1
Update PiVPN config:
sudo nano /etc/pivpn/wireguard/setupVars.conf
Change pivpnHOST to your DuckDNS domain.
Security Best Practices
Strengthen security:
1. Change default SSH port:
sudo nano /etc/ssh/sshd_config
# Change: Port 22 → Port 2222
sudo systemctl restart ssh
2. Disable password authentication (use SSH keys):
sudo nano /etc/ssh/sshd_config
# Set: PasswordAuthentication no
3. Enable firewall:
sudo apt install ufw
sudo ufw allow 51820/udp
sudo ufw allow 22/tcp # Or your custom SSH port
sudo ufw enable
4. Keep system updated:
# Automatic updates enabled during install
# Manual update anytime:
sudo apt update && sudo apt upgrade -y
5. Monitor logs:
sudo journalctl -u wg-quick@wg0
Advanced Configuration
Split Tunneling
Route only specific traffic through VPN:
Edit client config file:
[Interface]
PrivateKey = ...
Address = 10.6.0.2/24
DNS = 1.1.1.1
[Peer]
PublicKey = ...
Endpoint = yourhome.duckdns.org:51820
# Only route home network through VPN
AllowedIPs = 192.168.1.0/24
# Or route everything except local:
# AllowedIPs = 0.0.0.0/1, 128.0.0.0/1
Access Local Services
Access Pi-hole, NAS, or other services:
Just connect to VPN, then access by local IP:
- Pi-hole: http://192.168.1.50/admin
- NAS: http://192.168.1.100
- Security camera: http://192.168.1.25
Multiple Users
Create clients for family members:
pivpn add
# Name: dad-phone
pivpn add
# Name: mom-laptop
pivpn add
# Name: kid-tablet
Each gets own config/QR code.
View who's connected:
pivpn -c
Bandwidth Monitoring
Monitor VPN usage:
# Install vnStat
sudo apt install vnstat
sudo vnstat -i wg0
Shows data transferred through VPN.
Troubleshooting
Can't Connect to VPN
Check list:
- Pi is powered on and connected to network
- Port forwarding configured correctly (UDP 51820)
- Public IP hasn't changed (use DDNS if dynamic)
- Client config has correct endpoint
- Firewall on router not blocking UDP 51820
Test from Pi:
# Check WireGuard status
sudo wg show
# Check if port is listening
sudo netstat -tulpn | grep 51820
VPN Connects but No Internet
Solutions:
# Check IP forwarding enabled
cat /proc/sys/net/ipv4/ip_forward
# Should show: 1
# If not, enable:
echo "net.ipv4.ip_forward=1" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
Slow VPN Speeds
Optimize performance:
- Use ethernet on Pi (not Wi-Fi)
- Upgrade internet connection (VPN limited by upload speed)
- Pi 4 faster than Pi 3 for encryption
- Check server CPU:
top(shouldn't be maxed) - Reduce MTU in client config:
MTU = 1420
Public IP Changed
If using static IP and it changed:
- Find new IP:
curl ifconfig.me - Update client configs with new endpoint
- Or set up DDNS (see above)
Lost Client Config
Regenerate QR code:
pivpn -qr clientname
Or transfer config again:
cat ~/configs/clientname.conf
Performance Considerations
Expected speeds:
Raspberry Pi 4:
- Upload: 80-100 Mbps
- Download: 200+ Mbps
- Good for most home internet
Raspberry Pi 3:
- Upload: 40-60 Mbps
- Download: 100-150 Mbps
- Adequate for standard use
Bottleneck is usually your home upload speed, not the Pi.
When to Use Your VPN
Always use:
- Public Wi-Fi (coffee shops, hotels, airports)
- Unsecured networks
- When accessing home network remotely
Consider using:
- Avoid ISP throttling
- Access geo-restricted content (from your home region)
- Extra privacy layer
May not need:
- Already on secure home network
- Using HTTPS sites on trusted network
- When speed is critical (adds slight overhead)
Commercial VPN vs Personal VPN
Your Pi VPN: ✅ No monthly fees ✅ You control all data ✅ Access home network ✅ Appears from your home location ❌ Limited to your home IP ❌ No server location choice ❌ Limited by home upload speed
Commercial VPN: ✅ Multiple server locations ✅ Often faster speeds ✅ Professional infrastructure ❌ Monthly fees ($5-15) ❌ Trust third party with data ❌ Can't access home network
Use both: Commercial for privacy/speed, personal for home access!
Backup and Disaster Recovery
Backup configs:
pivpn backup
# Creates tar.gz with all configs
Store backup safely:
- Copy to USB drive
- Upload to cloud (encrypted)
- Print QR codes (old school but works!)
Restore after crash:
- Reinstall PiVPN
- Restore backup
- Clients reconnect with same configs
Integration with Other Projects
Combine with:
Pi-hole: Filter ads even when away from home NAS: Access files remotely and securely Home Assistant: Control smart home from anywhere Security cameras: View footage remotely
Just connect to VPN first, then access local services!
Cost Comparison
Personal VPN (One-time):
- Raspberry Pi 4: $35-55
- microSD card: $10-15
- Case + power: $15-20
- Total: ~$60-90 one-time
vs. Commercial VPN (Ongoing):
- NordVPN: $11.99/month
- ExpressVPN: $12.95/month
- Private Internet Access: $9.95/month
- Cost: $120-156 per year
Savings Year 1: $30-95 Savings Year 2+: $120-156 annually
What's Next?
Enhance your VPN:
- Set up redundant VPN (second Pi)
- Add Pi-hole for network-wide ad blocking
- Configure split tunneling per-app
- Create guest VPN network
- Monitor with Grafana dashboard
Resources
Official:
- PiVPN: pivpn.io
- WireGuard: wireguard.com
Communities:
- r/pivpn
- r/wireguard
- r/raspberry_pi
Help:
- PiVPN issues: github.com/pivpn/pivpn/issues
Final Thoughts
A personal VPN server is one of the most practical Pi projects:
✅ Daily use - Actually use it regularly ✅ Saves money - No monthly VPN fees ✅ Privacy - You control your data ✅ Secure - Protect yourself on public Wi-Fi ✅ Access home - Reach home network anywhere ✅ Set and forget - Runs 24/7 reliably
Perfect for frequent travelers, remote workers, or anyone who values privacy and security!
Ready to build your personal VPN? Follow this guide for secure, private internet access anywhere!