What will your VPN be used for?
With WireGuard, each device gets a private address (here in 10.8.0.x) and can reach the others through this encrypted tunnel, even behind a home router or on a mobile network. Typical uses: reaching your NAS or home automation from outside, administering your servers without exposing them to the Internet, linking two sites, or restricting your VPS's SSH access to the VPN alone.
Choose a KVM VPS
WireGuard runs in the Linux kernel. On a KVM VPS you have your own kernel and everything works straight away. On LXC, the kernel is shared with our server and WireGuard is not guaranteed: choose KVM for this project (see KVM or LXC). In terms of power, the VPS Mini is enough for personal or family use.
Your devices also need IPv6 to reach the VPS. Most French home routers and mobile plans have it; the IPv6 VPS guide explains how to check.
1. Install WireGuard on the VPS
apt update && apt install -y wireguard
Generate the server's key pair. umask 077 ensures the private key is readable by root only:
cd /etc/wireguard
umask 077
wg genkey | tee server.key | wg pubkey > server.pub
2. Generate each device's keys
Each device has its own key pair. The easiest way is to generate them in the device's WireGuard app (Windows, macOS, Android, iOS): it displays the public key for you to copy. On Linux, use the same command as above.
3. Configure the server
Create /etc/wireguard/wg0.conf:
[Interface]
Address = 10.8.0.1/24
ListenPort = 51820
PrivateKey = <contents of server.key>
# Laptop
[Peer]
PublicKey = <laptop public key>
AllowedIPs = 10.8.0.2/32
# Phone
[Peer]
PublicKey = <phone public key>
AllowedIPs = 10.8.0.3/32
Add one [Peer] block per device, each with its own address. So that devices can reach each other through the VPS, allow routing:
echo 'net.ipv4.ip_forward=1' > /etc/sysctl.d/90-wireguard.conf
sysctl --system
If you use a firewall such as ufw, open WireGuard's port:
ufw allow 51820/udp
ufw route allow in on wg0 out on wg0
The second rule lets traffic pass from one device to another through the VPS, which ufw blocks by default.
Start the VPN and enable it at boot:
systemctl enable --now wg-quick@wg0
wg show
4. Configure a device
In the WireGuard app, create a tunnel with this configuration (example for the laptop):
[Interface]
PrivateKey = <laptop private key>
Address = 10.8.0.2/24
[Peer]
PublicKey = <contents of server.pub>
Endpoint = [2001:db8::10]:51820
AllowedIPs = 10.8.0.0/24
PersistentKeepalive = 25
Replace 2001:db8::10 with your VPS's IPv6 address, keeping the square brackets. The AllowedIPs = 10.8.0.0/24 line only sends private-network traffic through the tunnel: the rest of your connection is unchanged. PersistentKeepalive keeps the tunnel open behind a home router or a mobile network.
Enable the tunnel, then test from the device:
ping 10.8.0.1
If the VPS replies, you are done. The wg show command on the server shows, for each device, the time of the last exchange ("latest handshake").
5. Going further: SSH through the VPN only
Once the VPN is in place, you can allow SSH only from the private network. With ufw, for example:
ufw allow from 10.8.0.0/24 to any port 22 proto tcp
Do not remove the SSH rule that is open to everyone until you have checked that the connection through the VPN works (ssh root@10.8.0.1): otherwise you risk locking yourself out.