Skip to content

27 WireGuard site to site ​

Two sites joined by an encrypted WireGuard tunnel across a shared network, routing each other's LANs.

What you practice ​

  • A WireGuard tunnel with wg-quick: keys, AllowedIPs and endpoints
  • Routing whole LANs through a tunnel
  • Seeing that only encrypted UDP crosses the shared network

Topology ​

NodeImageCPUs / memoryAddressesRole
gwadebian-131 / 1GiBmgmt 10.127.0.11; lan 192.168.1.1/24Site A gateway, wg0 10.99.0.1
gwbdebian-131 / 1GiBmgmt 10.127.0.12; lan 192.168.2.1/24Site B gateway, wg0 10.99.0.2
hadebian-131 / 1GiBmgmt 10.127.0.13; lan 192.168.1.10/24Host at site A
hbdebian-131 / 1GiBmgmt 10.127.0.14; lan 192.168.2.10/24Host at site B

Before you start ​

bash
vz image pull disk debian-13

Run it ​

bash
cd examples/27-wireguard-site-to-site
vz validate
vz up
vz node ls
ssh lab@10.127.0.11        # password: lab

First boot installs packages; give it a minute or two after vz up returns.

Try it ​

bash
ssh lab@10.127.0.11 'sudo wg show'
ssh lab@10.127.0.13 'traceroute -n 192.168.2.10'           # ha -> gwa -> (tunnel) -> gwb -> hb
ssh lab@10.127.0.11 'sudo tcpdump -ni mgmt -c 6 udp port 51820' &
ssh lab@10.127.0.13 'ping -c 3 192.168.2.10'               # tcpdump shows only UDP 51820
vz port down gwb/mgmt                                  # the tunnel's path is gone
vz port up gwb/mgmt                                    # traffic resumes within seconds

Notes ​

The keys in init/gwa and init/gwb were generated for this example and are public now. Use them only in this lab: wg genkey | tee private | wg pubkey > public makes new ones. The mgmt switch stands in for the internet between the two sites.

Clean up ​

bash
vz down
vz destroy --yes   # deletes the overlays and state of this lab