GuidesNetwork and VPNYour own WireGuard VPN

Set up a WireGuard VPN for you and your team on Debian

A WireGuard VPN on your own Debian server in about 15 minutes, so your team's phones and laptops reach your servers, admin panels and each other over an encrypted tunnel, without opening them to the whole internet.

Tested on Debian 13 (trixie) on a Melonslab server Updated October 29, 2026

Recommended server for this guide

VC-S Micro · 2 vCPU · 8 GB Memory · 250 GB Storage

Month to month, no lock-in 7-day money-back guarantee

These steps were tested on VC-P Alloy. This uses so little that VC-S Micro, with the same number of vCPUs and memory on an older CPU, is enough at a small scale and costs less.

€7.99/mo

Deploy now
On this page

What you will set up

A WireGuard server that your team's phones, laptops and other servers connect to. Every device gets its own address inside the tunnel, in 10.8.0.0/24. While connected, a device:

  • reaches the VPN server and anything that listens on it, such as SSH, an admin panel or a database, and
  • reaches the other devices and servers in the tunnel.

The rest of the device's traffic, such as ordinary browsing, keeps using its own internet connection, so the VPN only carries what it is for. If you also want a device to send all its traffic through the server, for example on public Wi-Fi, see the optional section at the end.

Before you start

You need:

  • a server with Debian 13 and root access,
  • an IPv4 address on the server, so devices can reach it from any network, and
  • the WireGuard app on each device (for Android, iOS, Windows, macOS and Linux, from wireguard.com).

The examples use 203.0.113.10 for the server's IPv4 address. Replace it with your own throughout.

1. Install WireGuard

apt update
apt install -y wireguard qrencode

qrencode puts a configuration on your phone's screen as a QR code.

2. Create keys

Every side of the tunnel has a private key, which never leaves it, and a public key, which you give to the other side.

cd /etc/wireguard
umask 077
wg genkey | tee server.key | wg pubkey > server.pub
wg genkey | tee phone.key | wg pubkey > phone.pub

umask 077 keeps the key files readable by root only.

3. Turn on forwarding

Devices in the tunnel reach each other through the server, so it has to pass traffic between them:

echo "net.ipv4.ip_forward = 1" > /etc/sysctl.d/99-wireguard.conf
sysctl --system

4. Configure the server

Create /etc/wireguard/wg0.conf:

[Interface]
Address = 10.8.0.1/24
ListenPort = 51820
PrivateKey = SERVER_PRIVATE_KEY

[Peer]
# phone
PublicKey = PHONE_PUBLIC_KEY
AllowedIPs = 10.8.0.2/32

Replace SERVER_PRIVATE_KEY with the output of cat server.key and PHONE_PUBLIC_KEY with the output of cat phone.pub. The server is 10.8.0.1 inside the tunnel, and the phone gets 10.8.0.2.

5. Start WireGuard

systemctl enable --now wg-quick@wg0
wg show

wg show lists the interface and the phone as a peer. WireGuard now also starts on every boot.

6. Connect your first device

Create /etc/wireguard/phone.conf, the configuration the phone will use:

[Interface]
PrivateKey = PHONE_PRIVATE_KEY
Address = 10.8.0.2/32

[Peer]
PublicKey = SERVER_PUBLIC_KEY
Endpoint = 203.0.113.10:51820
AllowedIPs = 10.8.0.0/24
PersistentKeepalive = 25

Replace PHONE_PRIVATE_KEY with cat phone.key and SERVER_PUBLIC_KEY with cat server.pub. AllowedIPs = 10.8.0.0/24 sends only traffic for the tunnel's addresses through it; everything else uses the phone's own connection.

To load it on the phone, show it as a QR code and scan it with the WireGuard app:

qrencode -t ansiutf8 < phone.conf

On a laptop, import phone.conf into the WireGuard app instead.

7. Check that it works

Connect, then reach the server at its tunnel address. From a laptop:

ssh root@10.8.0.1

On the server, wg show now shows a "latest handshake" for the device. Test with a real connection like this rather than ping, which can succeed even where other traffic is blocked.

Keep admin tools on the tunnel only

The point of the VPN is that internal tools no longer need to be open to the internet. Make a service listen only on the tunnel address, 10.8.0.1, or, with ufw on as in the security guide, allow its port on the tunnel only. For an admin panel on port 8080:

ufw allow in on wg0 to any port 8080 proto tcp

Your devices reach it at http://10.8.0.1:8080 while connected, and the rest of the internet does not reach it at all. Before you close SSH to the internet in the same way, check from a connected device that ssh root@10.8.0.1 works, and keep the provider console as a way back in.

Adding more devices

Each device needs its own keys and address. For a laptop, create keys:

cd /etc/wireguard
umask 077
wg genkey | tee laptop.key | wg pubkey > laptop.pub

Add a peer to the end of wg0.conf, with the next free address:

[Peer]
# laptop
PublicKey = LAPTOP_PUBLIC_KEY
AllowedIPs = 10.8.0.3/32

Then load the new peer into the running WireGuard:

wg syncconf wg0 <(wg-quick strip wg0)

wg syncconf changes only what differs, so connected devices stay connected. systemctl restart wg-quick@wg0 would also work, but cuts connected devices off for a few seconds.

The laptop's own configuration is the phone's with its private key and address swapped in.

Let devices reach each other

With ufw on, as in the security guide, the server drops traffic from one device to another until you allow it:

ufw route allow in on wg0 out on wg0

Then a device reaches the others at their tunnel addresses, such as 10.8.0.3.

Connect another server

Your other servers can join the tunnel like any device, so your team reaches them at a tunnel address too. On the other server, install WireGuard and create its keys as in steps 1 and 2, then create its /etc/wireguard/wg0.conf:

[Interface]
Address = 10.8.0.10/32
PrivateKey = DB_PRIVATE_KEY

[Peer]
PublicKey = SERVER_PUBLIC_KEY
Endpoint = 203.0.113.10:51820
AllowedIPs = 10.8.0.0/24
PersistentKeepalive = 25

On the VPN server, add it as a peer with AllowedIPs = 10.8.0.10/32, load it with wg syncconf as above, and start WireGuard on the other server with systemctl enable --now wg-quick@wg0. Your devices then reach it at 10.8.0.10, once you have allowed traffic between peers as in Let devices reach each other. Give servers addresses from 10.8.0.10 upwards, so they are easy to tell apart from people's devices.

Removing a device

In /etc/wireguard/wg0.conf, delete the device's [Peer] section. Then load the change and delete its files:

wg syncconf wg0 <(wg-quick strip wg0)
rm /etc/wireguard/laptop.key /etc/wireguard/laptop.pub /etc/wireguard/laptop.conf

The laptop can no longer connect, and the other devices stay connected. Do this the same day someone leaves the team.

Send all traffic through the server

For your own devices on networks you do not trust, such as hotel or café Wi-Fi, you can send all of a device's traffic through your server instead. The server then shares its IPv4 address with the device, and gives it its own IPv6 address from the server's /64.

Install nftables, which shares the address:

apt install -y nftables

Find your network interface and IPv6 range:

ip route show default
ip -6 addr show scope global

The first shows the interface after dev, usually eth0, and the second your IPv6 range, such as 2001:db8:1f::/64. Turn on IPv6 forwarding as well:

cat >> /etc/sysctl.d/99-wireguard.conf <<EOF
net.ipv6.conf.all.forwarding = 1
net.ipv6.conf.eth0.proxy_ndp = 1
EOF
sysctl --system

On Melonslab, your /64 is on the network link rather than routed to your server, so the server has to answer for each device's IPv6 address. proxy_ndp lets it, together with one proxy entry per device. Without it, IPv4 works in the tunnel and IPv6 silently does not. Your server's own IPv6 route is set statically, so turning on forwarding does not affect it.

Add these lines to the [Interface] section of wg0.conf, and add the phone's IPv6 address to its [Peer]:

PostUp = nft add table ip wireguard
PostUp = nft add chain ip wireguard postrouting "{ type nat hook postrouting priority srcnat; }"
PostUp = nft add rule ip wireguard postrouting ip saddr 10.8.0.0/24 oifname eth0 masquerade
PostDown = nft delete table ip wireguard
PostUp = ip -6 neigh add proxy 2001:db8:1f::100 dev eth0
PostDown = ip -6 neigh del proxy 2001:db8:1f::100 dev eth0
AllowedIPs = 10.8.0.2/32, 2001:db8:1f::100/128

Restart WireGuard with systemctl restart wg-quick@wg0, so the PostUp lines run. In the phone's configuration, add the IPv6 address and DNS servers to [Interface], and send everything through the tunnel:

Address = 10.8.0.2/32, 2001:db8:1f::100/128
DNS = 1.1.1.1, 2606:4700:4700::1111
AllowedIPs = 0.0.0.0/0, ::/0

With ufw on, add its two WireGuard rules from the security guide. To check, open ifconfig.co on the device: it shows the phone's own IPv6 address, 2001:db8:1f::100, or the server's IPv4 address, 203.0.113.10. Each further device needs its own IPv6 address, such as 2001:db8:1f::101, with its own pair of proxy lines; when you remove a device, remove its proxy entry with ip -6 neigh del proxy before deleting its lines.

Troubleshooting

The device never connects. wg show on the server shows no "latest handshake" for it. Check that the Endpoint is your server's IPv4 address and that UDP port 51820 reaches the server. Debian does not turn on a firewall by default. If you use ufw as in the security guide, add its two WireGuard rules.

The device connects, but cannot reach another device or server. Check that forwarding is on with sysctl net.ipv4.ip_forward, that ufw allows traffic between peers as in Let devices reach each other, and that the device's AllowedIPs covers 10.8.0.0/24.

With all traffic through the server, IPv4 works but IPv6 does not. Check that forwarding and proxy_ndp are on, and that the device's address has a proxy entry:

sysctl net.ipv6.conf.all.forwarding net.ipv6.conf.eth0.proxy_ndp
ip -6 neigh show proxy

Running a VPN for customers?

These steps are for a VPN you, your household or your team use. Public VPN, proxy and exit services are not covered by our plans, and need a written agreement with our sales team before you start.

Run it on your own server

VC-S Micro

€7.99/mo

vCPU
2
Memory
8 GB
Storage
250 GB
Transfer
10 TB
Standard
HDD · RAID 10
  • Full root access
  • Native /64 IPv6
  • RAID-protected storage
  • Malmö, Sweden
  • Month to month, no lock-in
  • 7-day money-back guarantee

These steps were tested on VC-P Alloy. This uses so little that VC-S Micro, with the same number of vCPUs and memory on an older CPU, is enough at a small scale and costs less.

All guides