WireGuard Site-to-Site VPN Setup on Ubuntu 24.04 and Debian 12
This deep-dive covers wireguard site to site vpn ubuntu with actionable analysis, practical implications, and expert insights.
Why WireGuard Beats Legacy IPsec and OpenVPN for Site-to-Site Links
Connecting an office LAN, homelab cluster, and cloud VPC used to require verbose IPsec policies or userspace OpenVPN daemons that bottlenecked single CPU cores. WireGuard ships directly inside the modern Linux kernel on Ubuntu 24.04 and Debian 12, uses modern cryptography (ChaCha20-Poly1305 and Curve25519), and fits an entire site-to-site configuration into fewer than 25 lines per gateway.
Network Topology Plan
Before writing any configuration, map out non-overlapping subnets so routing remains unambiguous:
| Site | Tunnel IP (wg0) | Local LAN Subnet | Public Endpoint |
|---|---|---|---|
| Site A (Primary Gateway) | 10.100.0.1/24 | 10.20.0.0/24 | 203.0.113.10:51820 |
| Site B (Branch / Cloud) | 10.100.0.2/24 | 10.30.0.0/24 | 198.51.100.20:51820 |
Step 1: Install WireGuard and Generate Keys on Both Gateways
Install the WireGuard utilities on both Site A and Site B:
sudo apt update
sudo apt install -y wireguard wireguard-tools iproute2
Generate locked-down private and public keys on each gateway, plus one shared preshared key on Site A:
# Run on BOTH Site A and Site B
umask 077
wg genkey | sudo tee /etc/wireguard/private.key | wg pubkey | sudo tee /etc/wireguard/public.key
# Run on Site A only, then copy securely to Site B
wg genpsk | sudo tee /etc/wireguard/preshared.key
Print the public keys so you can reference them in the peer blocks:
sudo cat /etc/wireguard/public.key
Step 2: Enable Kernel IP Forwarding
Both gateways must forward packets between their physical NIC and the wg0 interface. Create a persistent sysctl drop-in on both servers:
cat <<'EOF' | sudo tee /etc/sysctl.d/99-wireguard.conf
net.ipv4.ip_forward = 1
net.ipv6.conf.all.forwarding = 1
EOF
sudo sysctl --system
Step 3: Configure Site A (/etc/wireguard/wg0.conf)
Replace the placeholder keys and adjust eth0 if your primary interface name differs (check with ip -br link):
[Interface]
Address = 10.100.0.1/24
ListenPort = 51820
PrivateKey = <SITE_A_PRIVATE_KEY>
MTU = 1420
[Peer]
PublicKey = <SITE_B_PUBLIC_KEY>
PresharedKey = <SHARED_PRESHARED_KEY>
Endpoint = 198.51.100.20:51820
AllowedIPs = 10.100.0.2/32, 10.30.0.0/24
PersistentKeepalive = 25
Notice that AllowedIPs serves two roles in WireGuard: it tells wg-quick which kernel routes to install and enforces cryptokey routing so only Site B can send packets from 10.30.0.0/24.
Step 4: Configure Site B (/etc/wireguard/wg0.conf)
Mirror the configuration on Site B, pointing back to Site A's subnet:
[Interface]
Address = 10.100.0.2/24
ListenPort = 51820
PrivateKey = <SITE_B_PRIVATE_KEY>
MTU = 1420
[Peer]
PublicKey = <SITE_A_PUBLIC_KEY>
PresharedKey = <SHARED_PRESHARED_KEY>
Endpoint = 203.0.113.10:51820
AllowedIPs = 10.100.0.1/32, 10.20.0.0/24
PersistentKeepalive = 25
Lock down file permissions on both gateways:
sudo chmod 600 /etc/wireguard/wg0.conf
Step 5: Open Firewall Rules and Start the Tunnel
Allow UDP port 51820 and permit routed forwarding across wg0 in UFW on both servers:
sudo ufw allow 51820/udp comment 'WireGuard VPN'
sudo ufw route allow in on wg0 out on eth0
sudo ufw route allow in on eth0 out on wg0
sudo ufw reload
Enable and start the WireGuard systemd unit on both gateways:
sudo systemctl enable --now wg-quick@wg0
sudo wg show
Step 6: Verify End-to-End Connectivity and Throughput
Test both the tunnel endpoints and hosts behind each LAN gateway:
# From Site A
ping -c 4 10.100.0.2
ip route get 10.30.0.15
# Measure encrypted tunnel throughput with iperf3
# On Site B: iperf3 -s -B 10.100.0.2
# On Site A: iperf3 -c 10.100.0.2 -P 4
If LAN machines on Site A use a separate upstream router rather than the Linux gateway as their default gateway, add a single static route on your Site A router pointing 10.30.0.0/24 to the Site A Linux gateway's LAN IP (and vice versa on Site B).
Summary
WireGuard gives Ubuntu 24.04 and Debian 12 networks a clean, auditable site-to-site VPN without daemon bloat. By pairing strict AllowedIPs, a 256-bit preshared key, UFW route rules, and systemd persistence, your inter-site traffic stays fast and resilient across reboots.
Was this technical analysis helpful?
Your feedback informs our benchmark updates and ongoing article audits.
FAQ
Frequently Asked Questions
Structured for search engines and AI answer systems (AEO/GEO).
This almost always means either net.ipv4.ip_forward=1 is not enabled, UFW is dropping forwarded packets (DEFAULT_FORWARD_POLICY=DROP), or the LAN router does not have a static route pointing the remote subnet to the WireGuard gateway.
WireGuard defaults to MTU 1420 on standard 1500-byte Ethernet links (80 bytes of IPv4/UDP/WireGuard overhead). If your ISP uses PPPoE (MTU 1492), set MTU = 1412 or 1380 to prevent packet fragmentation.
Yes. Adding a 256-bit PresharedKey generated via wg genpsk adds an extra layer of post-quantum symmetric security with zero measurable performance cost.
Run sudo wg show on either gateway. A healthy tunnel displays a recent latest handshake timestamp (under 2 minutes) and incrementing transfer counters for both received and sent bytes.
More answers in our FAQ hub.
Newsletter
Practical Linux & Applied AI Newsletter
Get new tested tutorials and benchmark comparisons delivered directly to your inbox. Zero spam.
Join Weekly guides readers getting our weekly digest.
- Practical Linux administration & terminal workflows
- Tested open-source AI setups & benchmarks
- Zero spam - unsubscribe anytime