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

<div id="bkmrk-">---

</div>## System Requirements

- Ubuntu Server 20.04 or later
- Static IP address
- Root or sudo privileges
- Port forwarding access on your router

<div id="bkmrk--1">---

</div>## 1. Update the System

```
sudo apt update && sudo apt upgrade -y
```

<div id="bkmrk--2">---

</div>## 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
```

<div id="bkmrk--3">---

</div>## 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)

<div id="bkmrk--4">---

</div>## 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
```

<div id="bkmrk--5">---

</div>## 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.

<div id="bkmrk--6">---

</div>## 6. Connect Client Devices

- **Mobile:** Install the WireGuard app and scan the QR code
- **Desktop:** Import the `.conf` file into the WireGuard app

<div id="bkmrk--7">---

</div>## 7. Common PiVPN Commands

- Show connected clients:

```
pivpn -c
```

- List all profiles:

```
pivpn -l
```

- Revoke a client profile:

```
pivpn revoke
```

- Update PiVPN:

```
pivpn update
```

<div id="bkmrk--8">---

</div>## 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.