Skip to main content

Installing PiVPN with WireGuard on Ubuntu Server

This guide provides step-by-step instructions to install PiVPN using the WireGuard protocol on an Ubuntu Server system. PiVPN simplifies the process of setting up a secure and private VPN server.


System Requirements

  • Ubuntu Server 20.04 or later

  • Static IP address

  • Root or sudo privileges

  • Port forwarding access on your router


1. Update the System

sudo apt update && sudo apt upgrade -y

2. Set a Static IP Address (if not already set)

Edit your netplan configuration file:

sudo nano /etc/netplan/00-installer-config.yaml

Example configuration:

network:
  version: 2
  ethernets:
    eth0:
      dhcp4: no
      addresses:
        - 192.168.1.100/24
      gateway4: 192.168.1.1
      nameservers:
        addresses: [1.1.1.1, 8.8.8.8]

Apply the changes:

sudo netplan apply

3. Install PiVPN

Run the automated installation script:

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

During installation:

  • Select the user for managing VPN (typically your primary user)

  • Choose WireGuard as the VPN protocol

  • Allow PiVPN to manage firewall rules

  • Choose a port (default is 51820/UDP)

  • Select a DNS provider (Cloudflare, Google, or your own Pi-hole if available)


4. Configure WireGuard Profiles

To add a new VPN client:

pivpn add

Enter a name when prompted. This creates a .conf file stored in:

/home/<user>/configs/

To display a QR code for mobile devices:

pivpn -qr

5. Configure Router Port Forwarding

Log in to your router and forward the selected WireGuard port (e.g., 51820/UDP) to your Ubuntu Server's static IP address.


6. Connect Client Devices

  • Mobile: Install the WireGuard app and scan the QR code

  • Desktop: Import the .conf file into the WireGuard app


7. Common PiVPN Commands

  • Show connected clients:

pivpn -c
  • List all profiles:

pivpn -l
  • Revoke a client profile:

pivpn revoke
  • Update PiVPN:

pivpn update

Conclusion

You now have a secure WireGuard VPN running on Ubuntu Server using PiVPN. Connect remotely, enhance privacy, and safely route your traffic through your home network. Regularly check for updates to keep your VPN secure and performant.