23 de febrero de 2025

Protocol for Setting Up OpenVPN on Raspberry Pi Using PiVPN

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:

  1. Select OpenVPN when prompted.

  2. Set Static IP Address
    • The installer will ask if you want to set a static IP.
    • Accept the default or manually configure one.

  3. Select UDP or TCP
    • UDP (default, recommended) for better performance.
    • TCP for firewall bypassing but slower speed.

  4. Choose Port (Default: 1194)
    • You can change it if needed.

  5. Choose Encryption Settings
    • Select RSA key size (default: 2048-bit or 4096-bit for stronger security).

  6. Select DNS Provider
    • Choose from OpenDNS, Google, Cloudflare, or a custom DNS.

  7. 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:

  1. Log in to your router’s admin panel.
  2. Locate Port Forwarding settings.
  3. Forward UDP Port 1194 to your Raspberry Pi’s local IP address.
  4. 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):

    1. Install the OpenVPN client from openvpn.net.
    2. Import the .ovpn file.
    3. Click Connect.
  • Android/iOS:

    1. Install OpenVPN Connect from the App Store or Google Play.
    2. Import the .ovpn file.
    3. 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.