This guide will walk you through installing and configuring OpenVPN on a Raspberry Pi using PiVPN.
1. Prerequisites
- Raspberry Pi (Raspberry Pi 3, 4, or 5 recommended)
- Raspberry Pi OS (Lite or Full version)
- Internet connection
- SSH access or direct terminal access
- Static IP or Dynamic DNS (DDNS) for external access
2. Update and Upgrade System
Before installing OpenVPN, update the system:
sudo apt update && sudo apt upgrade -y
3. Install PiVPN
Run the PiVPN installation script:
curl -L https://install.pivpn.io | bash
This launches an interactive installer.
4. Configure OpenVPN
During installation, follow these steps:
- Select OpenVPN when prompted.
- Set Static IP Address
- The installer will ask if you want to set a static IP.
- Accept the default or manually configure one.
- Select UDP or TCP
- UDP (default, recommended) for better performance.
- TCP for firewall bypassing but slower speed.
- Choose Port (Default: 1194)
- You can change it if needed.
- You can change it if needed.
- Choose Encryption Settings
- Select RSA key size (default: 2048-bit or 4096-bit for stronger security).
- Select RSA key size (default: 2048-bit or 4096-bit for stronger security).
- Select DNS Provider
- Choose from OpenDNS, Google, Cloudflare, or a custom DNS.
- Choose from OpenDNS, Google, Cloudflare, or a custom DNS.
- Confirm Installation
- The script will install and configure OpenVPN.
5. Create a VPN User Profile
After installation, create a VPN user profile:
pivpn add
Follow the prompts to:
- Enter a username.
- Set a password (if required).
This will generate a .ovpn
configuration file stored in /home/pi/configs/
.
6. Configure Port Forwarding
To access the VPN from outside your network:
- Log in to your router’s admin panel.
- Locate Port Forwarding settings.
- Forward UDP Port 1194 to your Raspberry Pi’s local IP address.
- Save and restart your router.
7. Transfer the VPN Configuration File
To connect to your VPN, transfer the .ovpn
file to your client device:
- Use SCP, SFTP, or a USB drive to move the file.
- Example command for SCP:
scp pi@your_rpi_ip:/home/pi/configs/client.ovpn ~/Downloads/
- Alternatively, use an SFTP client like WinSCP or FileZilla.
8. Connect to OpenVPN
-
PC (Windows/macOS/Linux):
- Install the OpenVPN client from openvpn.net.
- Import the
.ovpn
file. - Click Connect.
-
Android/iOS:
- Install OpenVPN Connect from the App Store or Google Play.
- Import the
.ovpn
file. - Connect to your VPN.
9. (Optional) Set Up Dynamic DNS (DDNS)
If your public IP changes frequently, use DDNS:
- Sign up for a free No-IP or DuckDNS account.
- Configure DDNS on your router or install a DDNS client on the Raspberry Pi.
Example (for No-IP):
sudo apt install ddclient
sudo nano /etc/ddclient.conf
Add your No-IP credentials and domain.
10. Test the VPN
- Connect from an external network (e.g., mobile data).
- Visit whatismyipaddress.com to check if your public IP matches your VPN server.
That's it! 馃帀 Your OpenVPN server on Raspberry Pi is now set up.
Let me know if you need further assistance! 馃殌
References:
ChatGPT. (2025, February 23). How to set up OpenVPN with a dynamic IP using DDNS on Raspberry Pi. OpenAI. Retrieved from https://chat.openai.com
ChatGPT. (2025, February 23). A conceptual digital illustration representing VPN, Linux, Raspberry Pi OS, Raspberry Pi, and travel [AI-generated image]. OpenAI.
No hay comentarios:
Publicar un comentario