Home Blog Blog Details

How do you set up a Raspberry Pi as a VPN server?

July 03 2025
Ampheo

Inquiry

Global electronic component supplier AMPHEO PTY LTD: Rich inventory for one-stop shopping. Inquire easily, and receive fast, customized solutions and quotes.

QUICK RFQ
ADD TO RFQ LIST
Setting up a Raspberry Pi as a VPN server is a great way to access your home network securely from anywhere. One of the most popular ways to do this is by using PiVPN, which supports both WireGuard and OpenVPN.

Setting up a Raspberry Pi as a VPN server is a great way to access your home network securely from anywhere. One of the most popular ways to do this is by using PiVPN, which supports both WireGuard and OpenVPN. Here's a step-by-step guide using PiVPN with WireGuard (recommended for its speed and simplicity):

How do you set up a Raspberry Pi as a VPN server?


 What You’ll Need:

  • Raspberry Pi (any model, Pi 3 or newer is recommended)

  • Raspberry Pi OS installed and updated

  • Static IP or Dynamic DNS set up (for external access)

  • Router with port forwarding capability

  • Administrative (sudo) access


 Step-by-Step Setup Guide:

1. Update Your Pi

bash
 
sudo apt update && sudo apt upgrade -y

2. Install PiVPN

bash
 
curl -L https://install.pivpn.io | bash

This will launch a guided installer. Follow these steps:

  • Choose WireGuard (faster and more modern than OpenVPN)

  • Set a static IP (or choose one from your network)

  • Select the user (typically pi)

  • Let PiVPN automatically configure your firewall (UFW)

  • Open port 51820/UDP on your router for WireGuard


3. Set Up a VPN Profile

After installation:

bash
 
pivpn add
  • Enter a name for the client (e.g., myphone)

  • A .conf file will be created in /home/pi/configs


4. Transfer Configuration File to Your Device

Copy the .conf file to your phone or computer:

  • Use scp, sftp, or a USB stick

  • Or use QR code (for mobile):

    bash
     
    pivpn -qr

5. Install WireGuard App

On your mobile/PC, install the WireGuard app and import the configuration file (or scan the QR code).


6. Port Forwarding on Your Router

  • Log into your router's admin panel

  • Forward UDP port 51820 to your Pi's local IP address


7. (Optional) Use Dynamic DNS

If you don’t have a static IP, use Dynamic DNS:

  • Register with a service like No-IP, DuckDNS

  • Install the DDNS updater on your Pi


 Done!

Now you can connect securely to your home network from anywhere using WireGuard.


 Tips for Security:

  • Keep your Pi and packages up to date

  • Use strong passwords or SSH keys

  • Disable unused services

  • Backup your VPN keys

Ampheo