A working WireGuard site-to-site link makes the remote office’s 10.10.11.0/24 show up in your homelab as one more routed subnet. Once routing and firewall rules allow it, a laptop on one side can open an SMB share on the other with no VPN client installed. The mechanism is small. Each Ubuntu 24.04 gateway runs one WireGuard interface, and that interface’s AllowedIPs list acts as both a per-peer routing selector and an access list. Packets headed for the remote LAN get encrypted and sent to exactly one peer.
You need two Ubuntu 24.04 LTS (Noble Numbat) gateways, one per site. Each needs the wireguard apt package, a keypair, a config file in /etc/wireguard/, IP forwarding, routed firewall rules with no NAT, and a static route or two on each LAN. The WireGuard part is about 15 lines of config per side. Most of your time will go into firewall rules and routing, because that’s where site-to-site links fail.
| Decision | Choice | Why |
|---|---|---|
| Tunnel addressing | Dedicated /31 (10.10.9.0/31) | Two addresses, one per gateway, no overlap with either LAN |
| NAT between sites | None, purely routed | Remote hosts see real source IPs, and both sides can initiate connections |
| Service management | wg-quick@ systemd template unit | Documented by Ubuntu and adds routes from AllowedIPs automatically |
| Firewall | nftables (with a ufw equivalent) | Explicit forward rules scoped to the two LAN subnets |
| LAN client reachability | Gateway as default router, or a static route on the LAN router | Clients need a next hop for the remote subnet |
What You Need Before Building the Tunnel
- Two Ubuntu 24.04 LTS machines, one at each site. A dual-NIC mini PC works well as a dedicated gateway. A Raspberry Pi running Ubuntu Server is fine for a low-traffic remote office.
- SSH and sudo access to both gateways. Keep a second session open whenever you touch the firewall.
- Non-overlapping LAN ranges. If both sites use
192.168.1.0/24, renumber one before you start. Routing can’t tell two identical subnets apart. - A reachable UDP port on at least one gateway. That means a public IP on the gateway itself, or a port forward on the upstream router.
- A UPS on each gateway if the remote site sees flaky power. Once Step 6 enables the
wg-quick@unit, the tunnel comes back on boot. But repeated unclean shutdowns are rough on cheap SD cards and SSDs.
| Requirement | Details |
|---|---|
| OS | Ubuntu 24.04 LTS on both gateways |
| Package | wireguard from the Ubuntu archive (pulls in wireguard-tools) |
| Kernel support | Built into the stock Ubuntu 24.04 kernel, no DKMS needed (wireguard.com/install) |
| Firewall tooling | nftables or ufw (one policy manager; don’t load a separate ruleset on a ufw host) |
| Optional tools | traceroute, mtr-tiny, tcpdump for verification |
The addressing and config layout below follow Ubuntu’s own site-to-site WireGuard example from the Ubuntu Server documentation. The firewall rules, forwarding setup, routes, and hardening build on standard Linux networking practice.
How to Set Up a WireGuard Site-to-Site VPN on Ubuntu 24.04
Step 1: Plan the Topology and Addressing
Write the plan down before touching a config file. Every later step uses these values. A typo in one subnet produces confusing symptoms an hour later.
| Item | Site A (homelab, “alpha”) | Site B (remote office, “beta”) |
|---|---|---|
| LAN subnet | 10.10.10.0/24 | 10.10.11.0/24 |
| Gateway LAN IP | 10.10.10.1 | 10.10.11.1 |
| Gateway public IP | 203.0.113.10 | 198.51.100.20 |
| WireGuard interface | wgA | wgB |
| Tunnel IP | 10.10.9.0/31 | 10.10.9.1/31 |
| UDP listen port | 51000 | 51000 |
These are example values from Ubuntu’s documentation, with RFC 5737 documentation addresses standing in for public IPs. Swap in your own.
The tunnel gets its own /31 because only two hosts ever live on it. On systems that implement RFC 3021 point-to-point semantics, as Linux does, a /31 gives you two usable addresses and no broadcast address. That’s what a point-to-point link needs. If a device or tool in your path treats those two addresses as network and broadcast, use a /30 instead. Keeping it separate from both LANs gives each gateway a clear address on the tunnel. The routes stay readable, too.
Stay away from 192.168.0.0/24 and 192.168.1.0/24 for either site. They’re the defaults on most consumer routers. The day someone at the remote office plugs in a travel router, you’ll have an overlap.
Decide one more thing now: where does the WireGuard gateway sit on each LAN?
- Layout 1: the gateway is the LAN’s default router. LAN clients already send everything to it, so they reach the remote subnet with no extra routes.
- Layout 2: the gateway is a separate box behind your existing router. For example, a mini PC at
10.10.10.2behind a consumer router at10.10.10.1. The router needs a static route pointing the remote subnet at the WireGuard box (Step 5). The router must also port-forward UDP51000to it.
Check your interface names now. You’ll need them for the firewall rules.
ip -br link
lo UNKNOWN 00:00:00:00:00:00 <LOOPBACK,UP,LOWER_UP>
enp1s0 UP 52:54:00:12:34:01 <BROADCAST,MULTICAST,UP,LOWER_UP>
enp2s0 UP 52:54:00:12:34:02 <BROADCAST,MULTICAST,UP,LOWER_UP>
Throughout these examples, enp1s0 is the WAN-facing NIC and enp2s0 faces the LAN. On a single-NIC Layout 2 box, both roles are the same interface.
Step 2: Install WireGuard and Generate Keypairs on Both Gateways
Run this on both gateways:
sudo apt update
sudo apt install wireguard
Confirm the tools are present:
wg --version
wireguard-tools v<version> - https://git.zx2c4.com/wireguard-tools/
The version number varies with package updates. To see exactly which wireguard-tools build you have and where it came from, run apt policy wireguard-tools. Nothing in this guide depends on a specific tools version beyond what Ubuntu 24.04 ships; what matters is that the command runs and prints a version string.
Now generate the keypair. On site A:
# umask 077 makes the private key readable by root only
sudo sh -c 'umask 077; wg genkey > /etc/wireguard/wgA.key'
sudo sh -c 'wg pubkey < /etc/wireguard/wgA.key > /etc/wireguard/wgA.pub'
sudo cat /etc/wireguard/wgA.pub
On site B, the same commands with wgB:
sudo sh -c 'umask 077; wg genkey > /etc/wireguard/wgB.key'
sudo sh -c 'wg pubkey < /etc/wireguard/wgB.key > /etc/wireguard/wgB.pub'
sudo cat /etc/wireguard/wgB.pub
Each cat prints a 44-character base64 string ending in =. Copy each public key to the other site. The .pub file ends up root-only too because it was created under the same umask; that’s harmless, since public keys are safe to share. The private key files never leave the machine that generated them.
Check the permissions:
sudo ls -l /etc/wireguard/
-rw------- 1 root root 45 Nov 30 10:12 wgA.key
-rw------- 1 root root 45 Nov 30 10:12 wgA.pub
The key file is named after the interface on purpose. The config in Step 3 loads it with %i, which wg-quick expands to the interface name.
Step 3: Write the Config Files for Site A and Site B
On site A, create /etc/wireguard/wgA.conf:
# /etc/wireguard/wgA.conf (site A, homelab)
[Interface]
# Load the private key from a separate file so it never appears in this config
PostUp = wg set %i private-key /etc/wireguard/%i.key
Address = 10.10.9.0/31
ListenPort = 51000
[Peer]
# Site B, remote office
PublicKey = SITE_B_PUBLIC_KEY_FROM_wgB.pub
# Remote LAN plus the tunnel subnet
AllowedIPs = 10.10.11.0/24, 10.10.9.0/31
Endpoint = 198.51.100.20:51000
On site B, create /etc/wireguard/wgB.conf:
# /etc/wireguard/wgB.conf (site B, remote office)
[Interface]
PostUp = wg set %i private-key /etc/wireguard/%i.key
Address = 10.10.9.1/31
ListenPort = 51000
[Peer]
# Site A, homelab
PublicKey = SITE_A_PUBLIC_KEY_FROM_wgA.pub
AllowedIPs = 10.10.10.0/24, 10.10.9.0/31
Endpoint = 203.0.113.10:51000
# Keep NAT/firewall state alive on the remote office's upstream router
PersistentKeepalive = 25
Replace SITE_B_PUBLIC_KEY_FROM_wgB.pub and SITE_A_PUBLIC_KEY_FROM_wgA.pub with the actual base64 string each cat command printed in Step 2, not the literal placeholder text. A PublicKey line that still reads like a filename is one of the most common reasons a tunnel handshakes nowhere.
Lock both files down:
sudo chmod 600 /etc/wireguard/wgA.conf # use wgB.conf on site B
Three settings deserve a closer look.
AllowedIPs does two jobs. On the way out, wg-quick installs a kernel route for each listed prefix that an existing route doesn’t already cover, so traffic for 10.10.11.0/24 goes into wgA (the tunnel /31 gets no extra route because assigning the address already created one). On the way in, WireGuard drops any decrypted packet whose source address isn’t in the peer’s AllowedIPs. Together, these two jobs are called cryptokey routing. It also means a typo here gives you a tunnel that handshakes fine and carries nothing.
Endpoint tells this gateway where to send the first handshake. If both sites have static public IPs, set it on both sides, as Ubuntu’s example does. If site B sits behind carrier-grade NAT with no inbound port, set Endpoint only on B. Site A learns B’s current address from incoming packets.
PersistentKeepalive isn’t in Ubuntu’s baseline example. That example assumes both gateways have public, reachable addresses. In practice, remote offices usually sit behind a NAT router that forgets idle UDP mappings. A keepalive every 25 seconds keeps the mapping open, so site A can reach site B even after a quiet night.
This setting is only needed on a peer that sits behind NAT or a stateful firewall and must keep receiving inbound traffic after a period of inactivity; a gateway with a stable public IP and no NAT in front of it doesn’t need it. Add it to site A too if A is also behind NAT. The cost is a tiny packet every 25 seconds.
If you’re in Layout 2, forward UDP 51000 on the upstream router to the WireGuard box’s LAN IP now.
Step 4: Enable IPv4 Forwarding and Set Routed (Non-NAT) Firewall Rules
By default, Linux drops packets that arrive on one interface and are addressed to a host elsewhere. A gateway has to forward them. wg-quick doesn’t change this setting, so you set it yourself. Run this on both gateways:
echo 'net.ipv4.ip_forward = 1' | sudo tee /etc/sysctl.d/99-wireguard-forward.conf
sudo sysctl --system
sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1
If you use ufw, also check that /etc/ufw/sysctl.conf doesn’t set net/ipv4/ip_forward=0. ufw applies that file when it starts.
Why there’s no NAT between sites
Ubuntu’s guidance says it directly. Site-to-site traffic should be routed, with no masquerading. With pure routing, a NAS at site A sees the real 10.10.11.x address of the office PC. Firewall rules and logs stay meaningful, and either side can open connections. With NAT, every remote host collapses into the gateway’s tunnel IP. Connections started from the other direction also break.
Traffic between the two site LANs must never be NATed. If the gateway is also the internet router, its existing internet masquerade can stay. Make sure that rule matches only the WAN interface (oifname "enp1s0"). A broad rule like oifname != "lo" also catches wgA. That’s the most common way NAT leaks into a site-to-site tunnel.
Option 1: nftables
Warning: The ruleset below starts with
flush ruleset, which removes all existing nftables and iptables-nft rules, including any created byufwor Docker. If your gateway is also the internet router or runs containers, merge these rules into your existing ruleset instead of replacing it. A typo in the SSH rule can lock you out, so keep a console or second SSH session open.
Install and enable nftables:
sudo apt install nftables
sudo systemctl enable nftables
Write /etc/nftables.conf on site A:
# /etc/nftables.conf (site A)
#!/usr/sbin/nft -f
flush ruleset
define WAN_IF = "enp1s0"
define LAN_IF = "enp2s0"
define WG_IF = "wgA"
define LOCAL_LAN = 10.10.10.0/24
define REMOTE_LAN = 10.10.11.0/24
define WG_PEER = 198.51.100.20
define WG_PORT = 51000
table inet filter {
chain input {
type filter hook input priority filter; policy drop;
ct state established,related accept
ct state invalid drop
iifname "lo" accept
meta l4proto { icmp, ipv6-icmp } accept
# SSH only from the local LAN, never the WAN
iifname $LAN_IF ip saddr $LOCAL_LAN tcp dport 22 accept
# WireGuard only from the other gateway's public IP
iifname $WAN_IF ip saddr $WG_PEER udp dport $WG_PORT accept
}
chain forward {
type filter hook forward priority filter; policy drop;
ct state established,related accept
ct state invalid drop
# Routed traffic between the two LANs, nothing else
iifname $LAN_IF oifname $WG_IF ip saddr $LOCAL_LAN ip daddr $REMOTE_LAN accept
iifname $WG_IF oifname $LAN_IF ip saddr $REMOTE_LAN ip daddr $LOCAL_LAN accept
}
chain output {
type filter hook output priority filter; policy accept;
}
}
On site B, mirror it. Set WG_IF = "wgB", swap LOCAL_LAN and REMOTE_LAN, and set WG_PEER = 203.0.113.10. On a single-NIC Layout 2 gateway, set WAN_IF and LAN_IF to the same interface. More generally, in Layout 2 WAN_IF must be whichever NIC actually receives the forwarded UDP 51000 from the upstream router, not necessarily the one named enp1s0; if the handshake arrives on the LAN-facing NIC, set WAN_IF to that interface or the iifname match will drop it.
The ip saddr $WG_PEER match keeps strangers from probing your WireGuard port. The trade-off: if the remote site’s public IP changes, the tunnel goes silent until you update the rule. Drop the ip saddr match on whichever side faces a dynamic-IP peer.
In Layout 2, a normal port forward rewrites only the destination address, so the remote gateway’s public IP still arrives as the source. Some routers also source-NAT forwarded traffic, though. Check with sudo tcpdump -ni any udp port 51000 during a handshake, which also shows which interface the packet arrives on. If the source shown is the router’s LAN address rather than the remote public IP, drop the ip saddr $WG_PEER match, because it would block the forwarded handshake.
The ipv6-icmp accept admits all ICMPv6 addressed to the gateway, not just neighbor discovery. It’s deliberately broad so the gateway’s own IPv6 control traffic keeps working; on a gateway with IPv6 disabled you can drop ipv6-icmp from that line. This guide doesn’t configure IPv6 forwarding or IPv6 tunnel addresses; the tunnel is IPv4-only.
Check the syntax, then save the current ruleset and load the new one behind a dead-man switch:
sudo nft -c -f /etc/nftables.conf
# Save the ruleset that's active right now, before replacing it
sudo sh -c 'nft list ruleset > /run/nftables.backup'
# If you lock yourself out, restore that saved ruleset in 5 minutes
sudo systemd-run --on-active=5min --unit=nft-rollback /usr/sbin/nft -f /run/nftables.backup
sudo systemctl restart nftables
nft -c prints nothing when the file is valid. Because --on-active= is set, systemd-run creates a transient timer plus the service it triggers, and --unit=nft-rollback names both (nft-rollback.timer and nft-rollback.service). Confirm it’s armed with systemctl list-timers nft-rollback.timer. Open a new SSH session to confirm you can still log in.
If access is fine, cancel both the timer and the service it would trigger:
sudo systemctl stop nft-rollback.timer nft-rollback.service
If you forget to cancel it, the switch restores the ruleset that was active before you loaded the new one, which is a real rollback rather than an open firewall.
Option 2: ufw
If the gateway already uses ufw, add equivalent rules instead. Don’t also load the Option 1 ruleset or enable nftables.service on a ufw-managed host; the two would manage conflicting policies. On site A:
# WireGuard from the other gateway only
sudo ufw allow from 198.51.100.20 to any port 51000 proto udp
# Forwarding between LANs; "route" rules apply to forwarded traffic
sudo ufw route allow in on enp2s0 out on wgA from 10.10.10.0/24 to 10.10.11.0/24
sudo ufw route allow in on wgA out on enp2s0 from 10.10.11.0/24 to 10.10.10.0/24
sudo ufw reload
ufw drops forwarded traffic by default, so these route allow rules are the only path between the two LANs. They rely on IPv4 forwarding from earlier in this step; ufw applies /etc/ufw/sysctl.conf when it starts, so make sure that file doesn’t turn forwarding back off. Mirror the subnets and peer IP on site B.
Step 5: Add Static Routes So LAN Clients Reach the Remote Site
The gateways now know about both subnets, but your laptop has no route to the remote LAN. Every host sends traffic for unknown networks to its default gateway. So that default gateway has to know the next hop for the remote LAN.
Layout 1 (WireGuard gateway is the router): nothing to add. Clients already use 10.10.10.1 as their default gateway. wg-quick adds the 10.10.11.0/24 dev wgA route there in Step 6.
Layout 2 (WireGuard box behind another router): add a static route on the LAN router. In this example the WireGuard box is 10.10.10.2:
| Router setting | Site A value | Site B value |
|---|---|---|
| Destination | 10.10.11.0/24 | 10.10.10.0/24 |
| Next hop / gateway | 10.10.10.2 | 10.10.11.2 |
| Optional second route | 10.10.9.0/31 via 10.10.10.2 | 10.10.9.0/31 via 10.10.11.2 |
The second route only matters if LAN hosts need to reach the tunnel IPs themselves, for example for monitoring. Most consumer and prosumer routers have this under a Static Routes or Routing page.
The return path in Layout 2 works the same direction the outbound path does. The WireGuard box has a normal connected route to the LAN, so replies to a client’s packet go out that same LAN interface to the router, which delivers them to the client like any other local traffic. As long as the Step 5 static route exists on the router and nothing else has changed the WireGuard box’s LAN route, this just works.
Asymmetric routing becomes a real concern only in a different setup: one where the WireGuard box has some separate, direct path to LAN clients that bypasses the router entirely, such as a second NIC on the same segment with its own routing entry.
In that specific case, a strict stateful firewall on the router might see only one direction of a flow and drop it. If your router has no such second path and you still see odd drops, check for a missing route or an addressing mistake before suspecting asymmetry.
If the LAN router or a specific client is itself an Ubuntu machine, test the route first:
# Temporary; disappears on reboot
sudo ip route add 10.10.11.0/24 via 10.10.10.2
ip route get 10.10.11.10
10.10.11.10 via 10.10.10.2 dev enp2s0 src 10.10.10.50 uid 1000
cache
Then make it persistent with a separate Netplan file. Netplan merges it with your existing interface definition:
# /etc/netplan/60-site-b-route.yaml
network:
version: 2
ethernets:
enp2s0:
routes:
- to: 10.10.11.0/24
via: 10.10.10.2
sudo chmod 600 /etc/netplan/60-site-b-route.yaml
sudo netplan apply
On Ubuntu 24.04 Desktop, Netplan backs NetworkManager. The generated default file lives at /usr/lib/netplan/00-network-manager-all.yaml (Ubuntu 24.04 release notes). Don’t hand-edit that file. Add your own file under /etc/netplan/ or set the route in NetworkManager.
Step 6: Bring the Tunnel Up with wg-quick and systemd
Use the wg-quick@ systemd template unit instead of a bare wg-quick up. A manual up works until the next reboot. Then the tunnel is gone and nobody notices until Monday.
On site A:
# enable: start on every boot; --now: also start it immediately
sudo systemctl enable --now wg-quick@wgA
Created symlink /etc/systemd/system/multi-user.target.wants/wg-quick@wgA.service → /usr/lib/systemd/system/wg-quick@.service.
On site B:
sudo systemctl enable --now wg-quick@wgB
Check what wg-quick actually did. The excerpt below is representative rather than captured from a specific host. PIDs and timestamps will differ, and the exact lines depend on your config and wireguard-tools version. The order follows the wg-quick script: create the interface, load the peer config, add addresses, set the MTU, add routes, then run PostUp hooks.
sudo journalctl -u wg-quick@wgA --no-pager -n 10
wg-quick[1423]: [#] ip link add wgA type wireguard
wg-quick[1423]: [#] wg setconf wgA /dev/fd/63
wg-quick[1423]: [#] ip -4 address add 10.10.9.0/31 dev wgA
wg-quick[1423]: [#] ip link set mtu 1420 up dev wgA
wg-quick[1423]: [#] ip -4 route add 10.10.11.0/24 dev wgA
wg-quick[1423]: [#] wg set wgA private-key /etc/wireguard/wgA.key
Every line is a plain ip or wg command, which makes wg-quick easy to debug. There’s no route line for 10.10.9.0/31. The kernel created that one when the address was assigned. The MTU of 1420 is what wg-quick typically picks on a 1500-byte link after leaving room for WireGuard’s overhead; your value can differ with the path and with IPv6 transport.
systemctl status wg-quick@wgA --no-pager
● wg-quick@wgA.service - WireGuard via wg-quick(8) for wgA
Loaded: loaded (/usr/lib/systemd/system/wg-quick@.service; enabled; preset: enabled)
Active: active (exited) since Mon 2026-11-30 10:31:07 UTC; 12s ago
active (exited) is correct. The unit is a oneshot that runs the setup commands and exits. The kernel interface keeps running without a daemon.
To apply config changes later, restart the unit. The tunnel drops briefly while it tears down and rebuilds:
sudo systemctl restart wg-quick@wgA
wg-quick or systemd-networkd?
Both can own the wgA interface. They shouldn’t both try at once.
wg-quick@ unit | systemd-networkd | |
|---|---|---|
| Config files | /etc/wireguard/wgA.conf | /etc/systemd/network/*.netdev and *.network |
Routes from AllowedIPs | Added automatically | Only when you set RouteTable= in [WireGuardPeer] or add [Route] sections |
PostUp/PreDown hooks | Yes | No |
| Covered by Ubuntu’s site-to-site docs | Yes | No |
| Config change | Restart drops the tunnel briefly | networkctl reload reapplies in place |
I’d use wg-quick for this build. It matches Ubuntu’s documentation, and the config is one file you can read top to bottom. The journal shows every command it ran. Its weak spots are the lack of hooks into networkd ordering and the brief drop on restart.
Pick systemd-networkd if the gateway’s other interfaces are already networkd-native and you want one stack managing all of them. The catch is routing. networkd brings up the interface and peers but adds no routes for AllowedIPs unless you ask. That looks exactly like “handshake works, no traffic.” A minimal sketch looks like this:
# /etc/systemd/network/50-wgA.netdev
[NetDev]
Name=wgA
Kind=wireguard
[WireGuard]
# Must be readable by systemd-network: chown root:systemd-network, chmod 640
PrivateKeyFile=/etc/systemd/network/wgA.key
ListenPort=51000
[WireGuardPeer]
PublicKey=SITE_B_PUBLIC_KEY_FROM_wgB.pub
AllowedIPs=10.10.11.0/24,10.10.9.0/31
Endpoint=198.51.100.20:51000
# /etc/systemd/network/50-wgA.network
[Match]
Name=wgA
[Network]
Address=10.10.9.0/31
# Explicit route for the remote LAN; networkd won't add it from AllowedIPs on its own
[Route]
Destination=10.10.11.0/24
Site B mirrors both files: its own key, Address=10.10.9.1/31, site A’s public key and endpoint, AllowedIPs=10.10.10.0/24,10.10.9.0/31, and a [Route] with Destination=10.10.10.0/24.
Site B also gets PersistentKeepalive=25 in its [WireGuardPeer] section if it sits behind NAT, matching Step 3.
The systemd.netdev(5) man page defines AllowedIPs= as a comma-separated list and also allows the setting to be repeated, so one line per prefix works too. The single line above just keeps both prefixes in one place.
Treat this as a sketch to adapt, not the tested path in this guide. To switch an existing wg-quick gateway over, take these steps in order. First, stop wg-quick so wgA no longer exists. Per networkctl(1), reload creates a netdev from a new .netdev file, but some settings on an interface that already exists may not be applied. Next, confirm networkd is the active network service. Ubuntu Server 24.04’s Netplan setup normally renders to networkd, but a host managed by NetworkManager should stay on wg-quick.
sudo systemctl disable --now wg-quick@wgA
systemctl is-active systemd-networkd # expect: active
sudo chown root:systemd-network /etc/systemd/network/wgA.key
sudo chmod 640 /etc/systemd/network/wgA.key
sudo networkctl reload
networkctl status wgA
ip route show 10.10.11.0/24
sudo wg show wgA
networkctl status wgA should name 50-wgA.network as the interface’s network file and report it as configured. unmanaged means networkd isn’t handling the interface, and a missing route means the .network file wasn’t applied. Check all of this against the systemd.netdev(5), systemd.network(5), and networkctl(1) man pages on your system before you rely on it.
Step 7: Verify the Tunnel Beyond the Handshake
A handshake proves the keys and endpoint are right. It says nothing about forwarding, firewall rules, or LAN routes. Test each layer in order.
Layer 1: the WireGuard peer.
sudo wg show wgA
interface: wgA
public key: hY2kL0pQ7vN3xZ9bR4tW8mC1sD6fG5jK2aE0uI7oP3k=
private key: (hidden)
listening port: 51000
peer: Qm8vT2nR5xK1cL7wB3yH9dF4gJ6sA0eU2iO8pZ5tV1M=
endpoint: 198.51.100.20:51000
allowed ips: 10.10.11.0/24, 10.10.9.0/31
latest handshake: 14 seconds ago
transfer: 2.18 KiB received, 3.04 KiB sent
No latest handshake line just after startup is normal on a side without PersistentKeepalive. WireGuard only handshakes when there’s traffic to send. Ping something and check again.
Layer 2: gateway to gateway, and gateway to remote LAN.
ping -c 3 10.10.9.1 # site B's tunnel IP
ping -c 3 10.10.11.1 # site B's LAN IP
64 bytes from 10.10.11.1: icmp_seq=1 ttl=64 time=18.4 ms
64 bytes from 10.10.11.1: icmp_seq=2 ttl=64 time=18.1 ms
64 bytes from 10.10.11.1: icmp_seq=3 ttl=64 time=18.3 ms
Layer 3: a regular LAN client to a regular remote host. This is the end-to-end test. From a machine at site A (say 10.10.10.50), trace to a host at site B:
sudo apt install traceroute
traceroute -n 10.10.11.10
traceroute to 10.10.11.10 (10.10.11.10), 30 hops max, 60 byte packets
1 10.10.10.1 0.412 ms 0.388 ms 0.371 ms
2 10.10.9.1 18.204 ms 18.177 ms 18.150 ms
3 10.10.11.10 18.931 ms 18.902 ms 18.877 ms
Hop 2 is site B’s tunnel IP, so the packet crossed the tunnel as routed traffic. In Layout 2, expect one extra hop at the start: the LAN router, then the WireGuard box. For a running view of loss and latency, mtr is better:
sudo apt install mtr-tiny
mtr -rwc 20 10.10.11.10 # -r report mode, -w wide output, -c 20 probes
Layer 4: confirm no NAT. On site B’s gateway, watch the tunnel while the site A client pings:
sudo tcpdump -ni wgB icmp
10:42:13.118201 IP 10.10.10.50 > 10.10.11.10: ICMP echo request, id 7, seq 1, length 64
10:42:13.118940 IP 10.10.11.10 > 10.10.10.50: ICMP echo reply, id 7, seq 1, length 64
The source is the client’s real address, 10.10.10.50. If you see 10.10.9.0 instead while pinging from the LAN client, the usual cause is a masquerade rule catching forwarded traffic.
A ping sent from the gateway itself legitimately uses its tunnel address, so rule that out first. To confirm, run sudo nft list table ip nat and watch whether a masquerade rule’s counter rises while you ping. Then go back to the warning about broad NAT rules in Step 4. If no NAT rule matches, check the client’s routing and the forwarding path instead.
Layer 5: a quick MTU check. Confirm the interface MTU, then send a full-size packet with fragmentation disabled:
ip link show wgA
# 1392 bytes payload + 28 bytes ICMP/IP headers = 1420
ping -M do -s 1392 -c 3 10.10.11.10
Replies mean a packet sized to the tunnel MTU made it across the current path. They don’t prove every path or transport will behave the same, because encapsulation overhead, IPv4 versus IPv6 transport, intermediate links, PMTUD, and ICMP filtering all play a part.
A one-byte-larger ping will usually fail, often locally with a message too long error, though the exact behavior depends on the path and on ICMP handling. Treat this as a quick sanity check, not a precise path-MTU measurement. If small pings work but 1392-byte pings time out, the underlying path is smaller than 1500 bytes. PPPoE links are the usual culprit. Step 9 points to where that’s covered properly.
Step 8: Harden the Tunnel for Long-Term Use
A site-to-site link tends to run untouched for years. The keys never change, the firewall rules creep wider, and nobody notices when it goes down. None of the following comes from Ubuntu’s or WireGuard’s official docs as a mandated schedule. It’s operational practice. Ubuntu’s WireGuard security tips page is worth reading alongside it.
Rotate keys on a schedule you’ll actually keep
WireGuard renegotiates session keys automatically. The static keypairs in /etc/wireguard/ stay until you replace them. Pick a cadence you’ll stick to. Once a year is reasonable for a homelab. Rotate right away when a gateway’s disk is replaced, someone with root access leaves, or a backup with /etc/wireguard/ ends up somewhere it shouldn’t.
Rotation means a short planned outage, because both sides must change together. On site A:
sudo sh -c 'umask 077; wg genkey > /etc/wireguard/wgA.key.new'
sudo sh -c 'wg pubkey < /etc/wireguard/wgA.key.new > /etc/wireguard/wgA.pub.new'
sudo cat /etc/wireguard/wgA.pub.new
- Paste the new public key into
PublicKeyin site B’s/etc/wireguard/wgB.conf. - On site A, swap the files and restart:
sudo mv /etc/wireguard/wgA.key.new /etc/wireguard/wgA.key
sudo mv /etc/wireguard/wgA.pub.new /etc/wireguard/wgA.pub
sudo systemctl restart wg-quick@wgA
- On site B, restart
wg-quick@wgB. Runsudo wg showon both sides and confirm a fresh handshake.
Do site B’s keypair the same way afterward. Work over a path that doesn’t depend on the tunnel. Otherwise you’ll lose your SSH session to the remote gateway halfway through.
You can also add a preshared key for an extra symmetric layer on top of the public-key exchange. Generate it once on either gateway and copy it to the other over SSH, keeping tight permissions on both ends:
sudo sh -c 'umask 077; wg genpsk > /etc/wireguard/wgA.psk'
sudo chmod 600 /etc/wireguard/wgA.psk
Copy that file to site B as /etc/wireguard/wgB.psk; the contents must be byte-for-byte identical on both gateways. A PresharedKey = line in a wg-quick config takes the base64 key itself, not a file path, so load the file with a PostUp hook, the same way Step 3 loads the private key. Add one line to the [Interface] section on each side, using the other site’s real public key:
# In /etc/wireguard/wgA.conf, [Interface] section (site B's public key)
PostUp = wg set %i peer SITE_B_PUBLIC_KEY_FROM_wgB.pub preshared-key /etc/wireguard/%i.psk
# In /etc/wireguard/wgB.conf, [Interface] section (site A's public key)
PostUp = wg set %i peer SITE_A_PUBLIC_KEY_FROM_wgA.pub preshared-key /etc/wireguard/%i.psk
As in Step 3, replace each placeholder with the base64 string the matching cat command printed, not the filename. Restart both wg-quick@ units after adding the line. Then validate the runtime peer on each side:
sudo wg show wgA peers # exactly one peer, the other site's public key
sudo wg show wgA preshared-keys # that peer, followed by the loaded PSK
sudo cat /etc/wireguard/wgA.psk # must match the PSK printed above
Use wgB on site B. If peers lists a second, unexpected key, the public key in the PostUp line has a typo and wg set created a new peer instead of updating the real one; fix the line and restart. The PSK must be identical on both gateways, and the latest handshake should keep updating after the restart.
If you’d rather avoid the hook entirely, the documented native option is a PresharedKey = line in the [Peer] section holding the base64 string from the .psk file. It’s the simpler choice, and a reasonable default. The trade-off is that the key then lives inside the config file, which is already root-only at mode 600. The hook only buys you keeping key material out of the config.
Scope firewall rules to what each site needs
The Step 4 rules allow any host at one site to reach any host at the other. That’s convenient on day one. Once things work, narrow it. Say the remote office only needs the homelab’s NAS and DNS server. Replace the broad inbound forward rule on site A:
# In the forward chain of /etc/nftables.conf on site A
iifname $WG_IF oifname $LAN_IF ip saddr $REMOTE_LAN ip daddr 10.10.10.20 tcp dport { 445, 2049 } accept
iifname $WG_IF oifname $LAN_IF ip saddr $REMOTE_LAN ip daddr 10.10.10.53 meta l4proto { tcp, udp } th dport 53 accept
# Log anything else from the tunnel before the policy drops it
iifname $WG_IF log prefix "wg-s2s-drop: " limit rate 5/minute
Keep AllowedIPs equally tight. List the remote LAN and tunnel subnet, never 0.0.0.0/0. That way a compromised remote gateway can’t send packets claiming to come from anywhere else. Keep SSH off the WAN interface entirely, as the Step 4 ruleset does.
Monitor the handshake and the path
A tunnel can fail without any visible error. The handshake goes stale, or the handshake looks fine while a firewall change blocks forwarding. Check both. While traffic flows, WireGuard renews session keys with a fresh handshake roughly every two minutes. The 25-second keepalive on site B sends small packets so there’s always traffic to trigger that.
A recent handshake only proves the gateways can reach each other, though, not that LAN-to-LAN forwarding works. In this setup, a handshake older than about three minutes is a good sign something is wrong; tune the threshold if your traffic pattern differs.
Create /usr/local/bin/wg-s2s-check.sh on site A:
#!/usr/bin/env bash
# /usr/local/bin/wg-s2s-check.sh
IFACE="wgA"
MAX_AGE=180 # seconds
REMOTE_TEST="10.10.11.1" # site B gateway LAN IP; must answer ICMP from site A
now=$(date +%s)
# One peer per interface in this design; take the first line only
last=$(wg show "$IFACE" latest-handshakes | awk 'NR==1 {print $2}')
last=${last:-0}
age=$(( now - last ))
if [ "$last" -eq 0 ] || [ "$age" -gt "$MAX_AGE" ]; then
logger -t wg-s2s "WARN: $IFACE last handshake ${age}s ago"
exit 1
fi
if ! ping -c 3 -W 2 -q "$REMOTE_TEST" > /dev/null; then
logger -t wg-s2s "WARN: $IFACE handshake fresh but $REMOTE_TEST unreachable"
exit 1
fi
logger -t wg-s2s "OK: $IFACE handshake ${age}s ago"
Run it every five minutes with a systemd timer:
# /etc/systemd/system/wg-s2s-check.service
[Unit]
Description=Check WireGuard site-to-site tunnel health
[Service]
Type=oneshot
ExecStart=/usr/local/bin/wg-s2s-check.sh
# /etc/systemd/system/wg-s2s-check.timer
[Unit]
Description=Run WireGuard tunnel check every 5 minutes
[Timer]
OnBootSec=2min
OnUnitActiveSec=5min
[Install]
WantedBy=timers.target
sudo chmod 755 /usr/local/bin/wg-s2s-check.sh
sudo systemctl daemon-reload
sudo systemctl enable --now wg-s2s-check.timer
journalctl -t wg-s2s -n 5 --no-pager
Nov 30 11:05:02 alpha-gw wg-s2s[2210]: OK: wgA handshake 38s ago
Treat a failed ping as “look now,” not proof that WireGuard is down. The target may be rebooting, or a host firewall change may be dropping ICMP while the tunnel itself is fine. For a stronger signal, test a second always-on host as well, or replace the ping with a TCP check against a service you actually depend on across the link.
logger writes to the journal, which nobody reads at 2 a.m. Swap those lines for whatever alerting you already run, such as a push-notification service or your monitoring stack.
Step 9: Fix Common Site-to-Site Failures
Ubuntu keeps a general WireGuard troubleshooting page. These are the failures specific to this build.
No handshake at all
Why it happens: UDP 51000 isn’t reaching the other gateway. Common causes are a host firewall rule with the wrong peer IP, a missing port forward on the upstream router, a wrong Endpoint, or a pasted private key where the public key belongs.
Fix:
- Run
sudo wg showon both sides. Thepeer:key on site A must match site B’s/etc/wireguard/wgB.pubexactly, and the reverse. - Watch for packets on the receiving gateway:
sudo tcpdump -ni enp1s0 udp port 51000. If nothing arrives, the problem is upstream (router port forward or ISP). If packets arrive with no reply, look at the host firewall or keys. - Temporarily remove the
ip saddr $WG_PEERmatch in nftables if the peer’s public IP may have changed.
Handshake succeeds, but remote LAN hosts are unreachable
Why it happens: almost always AllowedIPs, a missing route, or forwarding. One peer’s AllowedIPs doesn’t cover the source or destination subnet, ip_forward is off, the forward chain doesn’t match, or the LAN router has no route back.
Fix: run ip route get 10.10.11.10 on the gateway and confirm it says dev wgA. Then confirm sysctl net.ipv4.ip_forward returns 1. Also check that the client’s default gateway has the Step 5 route. If all three check out, work through TBRT’s handshake-but-no-traffic troubleshooting guide. It covers AllowedIPs mismatches and MTU black holes in far more depth than fits here. That includes the “small pings work, large transfers stall” pattern from the Step 7 MTU check.
Tunnel works until the gateway reboots
Why it happens: it was brought up with a one-off sudo wg-quick up wgA, which doesn’t persist.
Fix:
sudo wg-quick down wgA
sudo systemctl enable --now wg-quick@wgA
systemctl is-enabled wg-quick@wgA
enabled
Remote hosts see the gateway’s tunnel IP instead of real client IPs
Why it happens: a masquerade rule is matching traffic leaving wgA. That’s usually a catch-all internet NAT rule, or a NAT line copied from a road-warrior VPN guide.
Fix: list the NAT rules with sudo nft list table ip nat, or sudo iptables -t nat -S if you’re on the iptables layer. Restrict masquerade to the WAN interface only, such as oifname "enp1s0" masquerade. Re-run the tcpdump -ni wgB icmp test from Step 7 and confirm the real source address appears. Also confirm the two LANs don’t overlap. Overlapping subnets are the usual reason someone added NAT in the first place.
Wrapping Up
You now have two Ubuntu 24.04 gateways passing routed, unNATed traffic between LANs. The tunnel survives reboots, and a timer complains when it doesn’t. Every device on either LAN reaches the other site without a VPN client. Remote hosts see real source addresses in their logs.
My take: WireGuard itself is the easy part. Most failures come from forwarding, firewall rules, and LAN routes, so when something breaks, check the layer Step 7 flags first. Put key rotation on the calendar now, too. The tunnel will run untouched long enough that you’ll forget otherwise.
| Step | Action | Applies To |
|---|---|---|
| 1 | Plan non-overlapping LANs and a /31 tunnel subnet | Both sites |
| 2 | apt install wireguard, generate a keypair per gateway | Both gateways |
| 3 | Write wgA.conf / wgB.conf with AllowedIPs, Endpoint, and PersistentKeepalive on any NAT’d peer | Both gateways |
| 4 | Enable ip_forward, add routed nftables or ufw rules, no NAT | Both gateways |
| 5 | Add static routes on LAN routers (Layout 2 only) | LAN routers or clients |
| 6 | systemctl enable --now wg-quick@wgX | Both gateways |
| 7 | Verify with wg show, ping, traceroute, tcpdump, MTU ping | Gateways and LAN clients |
| 8 | Rotate keys, narrow firewall scope, add a health-check timer | Both gateways |
| 9 | Work through handshake, routing, persistence, and NAT failures | As needed |