Bobay Stack

Networking & proxies / 2026-07-02

WireGuard three-node networking: a minimal working configuration

One cloud host, one home PVE, one laptop. Three configs, one set of keys, twenty lines to get them talking.

4 MIN READ BY BOBAY.TOP Updated 2026-07-08 ↖ All notes
WireGuard three-node networking: a minimal working configuration

The nice thing about WireGuard is that the config is the documentation: one file spells out who the peer is, which addresses are allowed, which endpoint to use. The annoying thing is that there's no central "who connects to whom" — every node has to know the other nodes' public keys.

Plan the addresses first

10.66.0.1   cloud host (has a public IP, acts as the hub)
10.66.0.2   home PVE (behind NAT, connects out to the hub)
10.66.0.3   laptop (roams around, connects out to the hub)

Pick a subnet that doesn't collide with anything — something like 10.66.0.0/24 will do. Don't use 192.168.1.0/24, it will fight with the home router.

Keys

wg genkey | tee private.key | wg pubkey > public.key
chmod 600 private.key

Generate one pair per machine. The private key doesn't go into a repo, doesn't go into notes — it stays on the machine in /etc/wireguard/.

The hub node

# /etc/wireguard/wg0.conf
[Interface]
Address = 10.66.0.1/24
ListenPort = 51820
PrivateKey = <hub private key>

[Peer]                 # home PVE
PublicKey = <PVE public key>
AllowedIPs = 10.66.0.2/32

[Peer]                 # laptop
PublicKey = <laptop public key>
AllowedIPs = 10.66.0.3/32

Leaf nodes (behind NAT)

[Interface]
Address = 10.66.0.2/24
PrivateKey = <local private key>

[Peer]
PublicKey = <hub public key>
Endpoint = <cloud host IP>:51820
AllowedIPs = 10.66.0.0/24
PersistentKeepalive = 25

PersistentKeepalive = 25 is the key part: a node behind NAT that sends nothing will have its mapping expire, and that shows up as "it worked, then a while later it can't connect." A heartbeat every 25 seconds keeps the path alive.

Three things you have to do

  1. Turn on forwarding (the hub needs to forward): sysctl -w net.ipv4.ip_forward=1, and write it into /etc/sysctl.d/
  2. Allow UDP 51820, otherwise the handshake packets never get in
  3. Routes have to be explicit: writing AllowedIPs alone isn't enough, the host side also needs a route to the peer's internal network (or NAT)

Troubleshooting order

wg show                    # check handshake time; over 2 minutes means it's not connected
ping 10.66.0.1             # test the tunnel itself first
tcpdump -i wg0 icmp        # tunnel is up but traffic fails; check whether packets are arriving

If the handshake time keeps saying "never", it's almost certainly the firewall or a wrong endpoint address; if the handshake is fine but traffic doesn't flow, it's almost certainly routing or NAT.

Settle the topology first, then talk about config

With three nodes, the problem you run into most often isn't the crypto parameters, it's routing loops and AllowedIPs fighting each other. Draw the topology first:

A (home) ── B (Hong Kong) ── C (Tokyo)
└────── direct connection? or does everything go through B?

If A and C also need to reach each other, there are two paths: let B forward (A's AllowedIPs lists only C's subnet, and B turns on net.ipv4.ip_forward=1), or let A connect directly to C (one more endpoint, but one hop fewer). Pick the path first, then write the next line of config.

The core difference between the three configs

Each node's [Peer] section only says "where I'm going", never "who's coming to me":

# B node: routes to A and C
[Peer]          # → A
PublicKey = <A_pub>
AllowedIPs = 10.10.0.2/32

[Peer]          # → C
PublicKey = <C_pub>
AllowedIPs = 10.10.0.3/32

Here AllowedIPs is a routing table, not an ACL. Write it too broadly (say 0.0.0.0/0) and all traffic gets shoved into that tunnel; do that on all three nodes at once and you've built a loop.

The three things most easily forgotten

  1. Kernel forwarding: relay nodes need sysctl -w net.ipv4.ip_forward=1, written into /etc/sysctl.d/, otherwise it's gone on reboot.
  2. MTU: the default is 1420; over PPPoE or double tunnels you often have to drop to 1280, otherwise large packets are silently dropped, which looks like "ping works, file transfer doesn't".
  3. Firewall: does ufw allow 51820/UDP by default? A lot of people only open TCP.

How to verify

Don't just look at "latest handshake" in wg show. What you actually need to test is end to end:

wg show                     # is there a handshake, is there traffic
ping -c 3 10.10.0.3         # reachable inside the tunnel
curl --interface wg0 ifconfig.me   # has the egress IP changed

The third one matters most: if the first two pass but the egress IP hasn't changed, the route isn't in effect and packets are still going out the physical NIC.

WireGuardnetworkingVPN

References

WireGuard quick start ↗ wg-quick man page ↗