Site-to-site WireGuard VPN connection with OpenWRT
I recently connected two sites, each behind its own OpenWrt router, with a WireGuard tunnel. The goal sounds simple: servers on both sides should reach each other by their LAN IPs, but only inter-site traffic should use the VPN. Everything else (internet, apt, container pulls) should keep leaving through each site's own WAN.
Getting there took a few wrong turns: a site that lost internet the moment the tunnel came up, a handshake that worked while no traffic flowed, and a server whose own WireGuard client silently hijacked its traffic. This post is the clean, working setup, done entirely in the LuCI web interface, followed by the troubleshooting notes I wish I'd had.
The design
- Site A (
192.168.13.0/24) runs the WireGuard server and listens on UDP 51820. - Site B (
192.168.14.0/24) is the client. It initiates the connection and keeps it alive. - The tunnel subnet is
10.13.0.0/24: A is10.13.0.1, B is10.13.0.2. - Traffic is routed, not NATed, so servers see each other's real IP addresses.
- Servers need no VPN software and no static routes. The routers do all of the split routing.
Addressing plan
| Item | Site A | Site B |
|---|---|---|
| Role | WireGuard server | WireGuard client |
| LAN subnet | 192.168.13.0/24 | 192.168.14.0/24 |
| Router LAN IP (server gateway) | 192.168.13.1 | 192.168.14.1 |
| wg0 tunnel address | 10.13.0.1/24 | 10.13.0.2/24 |
| Listen port | 51820/udp | — |
| Peer endpoint | — (B connects in) | Site A public IP or DDNS name, port 51820 |
| Peer Allowed IPs | 10.13.0.2/32, 192.168.14.0/24 | 10.13.0.0/24, 192.168.13.0/24 |
0.0.0.0/0 in a peer's Allowed IPs in this design. With "Route Allowed IPs" enabled, it turns the tunnel into that router's default route, and the site loses internet access the moment the VPN comes up. Also keep the two LANs, the tunnel subnet and each router's WAN-side network from overlapping.Prerequisites (both routers)
- OpenWrt 22.03 or newer (fw4/nftables). I used 23.05; 24.10 works the same.
- In System → Software, click Update lists, then install
luci-proto-wireguard. This also pulls inwireguard-toolsand the kernel module. Optionally installtcpdumpfor troubleshooting. - Reboot, so the WireGuard VPN protocol shows up in LuCI.
- In System → System → Time Synchronization, make sure the NTP client is enabled. WireGuard rejects handshakes with a timestamp older than the last one it accepted.
- Site A must be reachable on UDP 51820 from the internet. If A's WAN IP is private (it sits behind an ISP modem), forward the port on that modem. If the WAN IP falls in
100.64.0.0/10, A is behind CGNAT: get a public IP from the ISP, or swap the server and client roles.
Site A: WireGuard server
1. Create the wg0 interface
- Go to Network → Interfaces → Add new interface…, set the name to
wg0and the protocol to WireGuard VPN. - On the General Settings tab:
- Private Key: click Generate new key pair and copy the resulting Public Key. Site B needs it.
- Listen Port:
51820 - IP Addresses:
10.13.0.1/24
- On the Firewall Settings tab, assign the zone
vpn(created below).
2. Add site B as a peer
On the Peers tab, click Add peer:
| Field | Value |
|---|---|
| Description | site-B |
| Public Key | Site B's public key |
| Preshared Key | Empty, or identical on both sides |
| Allowed IPs | 10.13.0.2/32192.168.14.0/24 |
| Route Allowed IPs | ✔ checked |
| Endpoint / Keepalive | Leave empty (B connects in and sends keepalives) |
192.168.14.0/24 is mandatory: WireGuard's Allowed IPs is both a routing table and a source-address filter. Without this entry, A silently drops every packet from B's LAN, even though the handshake succeeds.3. Open the port on A's WAN
Go to Network → Firewall → Traffic Rules → Add: name Allow-WireGuard, protocol UDP, source zone wan, destination zone Device (input), port 51820, action accept.
The equivalent UCI config, for reference:
# /etc/config/network (Site A)
config interface 'wg0'
option proto 'wireguard'
option private_key '<SITE_A_PRIVATE_KEY>'
option listen_port '51820'
list addresses '10.13.0.1/24'
config wireguard_wg0
option description 'site-B'
option public_key '<SITE_B_PUBLIC_KEY>'
list allowed_ips '10.13.0.2/32'
list allowed_ips '192.168.14.0/24'
option route_allowed_ips '1'
# /etc/config/firewall (Site A only)
config rule
option name 'Allow-WireGuard'
option src 'wan'
option proto 'udp'
option dest_port '51820'
option target 'ACCEPT'
Site B: WireGuard client
1. Create the wg0 interface
- Go to Network → Interfaces → Add new interface… and create
wg0with protocol WireGuard VPN. - On the General Settings tab: generate a key pair and copy B's Public Key into A's peer. Leave Listen Port empty, and set IP Addresses to
10.13.0.2/24. - On the Advanced Settings tab, leave Use custom DNS servers empty.
- On the Firewall Settings tab, assign the zone
vpn.
192.168.0.2/24 address from an earlier attempt. The handshake worked fine, but A dropped everything the router sent, because that source IP wasn't in A's Allowed IPs. Double-check the tunnel addresses on both sides.2. Add site A as a peer
| Field | Value |
|---|---|
| Description | site-A |
| Public Key | Site A's public key |
| Allowed IPs | 10.13.0.0/24192.168.13.0/24not 0.0.0.0/0 |
| Route Allowed IPs | ✔ checked |
| Endpoint Host / Port | Site A's public IP or DDNS name / 51820 |
| Persistent Keep Alive | 25 |
# /etc/config/network (Site B)
config interface 'wg0'
option proto 'wireguard'
option private_key '<SITE_B_PRIVATE_KEY>'
list addresses '10.13.0.2/24'
config wireguard_wg0
option description 'site-A'
option public_key '<SITE_A_PUBLIC_KEY>'
option endpoint_host '<SITE_A_PUBLIC_IP_OR_DDNS>'
option endpoint_port '51820'
option persistent_keepalive '25'
list allowed_ips '10.13.0.0/24'
list allowed_ips '192.168.13.0/24'
option route_allowed_ips '1'
Key cross-check
| Router | wg0 → Private Key | Peer → Public Key |
|---|---|---|
| Site A | A private | B public |
| Site B | B private | A public |
Status → WireGuard shows each router's own public key at the top. Compare it character by character with what the other router has in its peer.
Firewall zone (both routers)
Go to Network → Firewall → Zones → Add:
| Field | Value |
|---|---|
| Name | vpn |
| Input / Output / Forward | accept / accept / accept |
| Masquerading | off (routed, servers see real IPs) |
| MSS clamping | on (prevents stalls on HTTPS/SMB) |
| Covered networks | wg0 |
| Forward to / from | lan / lan |
Afterwards, the zone overview must still show lan ⇒ wan next to the new lan ⇒ vpn and vpn ⇒ lan. The wan zone must keep Masquerading on, and wg0 must not be in the wan zone. Click Save & Apply, then restart wg0 in Network → Interfaces: on A first, then on B.
# /etc/config/firewall (both sites)
config zone
option name 'vpn'
option input 'ACCEPT'
option output 'ACCEPT'
option forward 'ACCEPT'
option masq '0'
option mtu_fix '1'
list network 'wg0'
config forwarding
option src 'lan'
option dest 'vpn'
config forwarding
option src 'vpn'
option dest 'lan'
The servers: keep them dumb
This is where the split tunnel pays off. Servers just use their local OpenWrt router as their only default gateway, and the router decides where each packet goes:
| Destination (from a site B server) | Server sends to | Router B sends via |
|---|---|---|
192.168.13.0/24, 10.13.0.0/24 | 192.168.14.1 | wg0 (VPN) |
| Everything else | 192.168.14.1 | WAN |
DHCP from the router is the easiest option. For a static IP with netplan:
network:
version: 2
ethernets:
ens160:
dhcp4: false
addresses: [192.168.14.208/24]
routes:
- to: default
via: 192.168.14.1 # site A servers: 192.168.13.1
nameservers:
addresses: [192.168.14.1] # site A servers: 192.168.13.1
Apply it with sudo netplan try, which rolls back automatically if you lose access. Remove old gateway4: lines and any manual routes to the other site.
Allow the remote site in the host firewall
# ufw (on a site B server; on site A use 192.168.14.0/24)
sudo ufw allow from 192.168.13.0/24
sudo ufw allow from 10.13.0.0/24
# firewalld
sudo firewall-cmd --permanent --zone=trusted --add-source=192.168.13.0/24
sudo firewall-cmd --permanent --zone=trusted --add-source=10.13.0.0/24
sudo firewall-cmd --reload
Watch out for VPN clients on the servers themselves
This one cost me the most time. ip route on a site B server looked perfect: default via 192.168.14.1. But it had no internet. The cause was a leftover wg-quick client on the server with AllowedIPs = 0.0.0.0/0. wg-quick puts its default route in a separate routing table (51820), selected via ip rule, so the main table looks innocent while all traffic disappears into another tunnel. Its DNS = line had also replaced the server's resolver, which broke apt.
ip rule # only rules 0, 32766, 32767 expected
ip route get 8.8.8.8 # must show: via 192.168.14.1
sudo wg show # any unexpected local WireGuard?
# not needed:
sudo systemctl disable --now wg-quick@wg0
# needed, but only for its own network: in /etc/wireguard/wg0.conf set
# AllowedIPs = 10.8.0.0/24 (instead of 0.0.0.0/0) and remove the DNS = line
On Docker and Kubernetes hosts, also make sure the container, pod and service CIDRs don't overlap 192.168.13.0/24, 192.168.14.0/24 or 10.13.0.0/24.
Verifying it works
| Where | Check | Expected |
|---|---|---|
| Both: Status → WireGuard | Latest handshake | Under 2 minutes ago, RX/TX increasing |
| B: Status → Routing | Routes | 0.0.0.0/0 → wan; 192.168.13.0/24 and 10.13.0.0/24 → wg0 |
| A: Status → Routing | Return route | 192.168.14.0/24 → wg0 |
| B: Network → Diagnostics | Ping 8.8.8.8, 10.13.0.1, 192.168.13.1 | All succeed |
| Site B server | ip route get 8.8.8.8 | via 192.168.14.1 |
| Site B server | ping 192.168.13.2, sudo apt update | Both work |
| Site A server | ping 192.168.14.208, sudo apt update | Both work |
To prove the internet does not go through the VPN, run traceroute -n 1.1.1.1 on a site B server. Hop 1 is 192.168.14.1, hop 2 is B's upstream gateway, and 10.13.0.1 never appears.
Troubleshooting
No handshake at all
- A isn't reachable: compare A's WAN IP (Status → Overview) with its real public IP. A private WAN IP means you need a port forward on the upstream modem. An address in
100.64.x.xmeans CGNAT. - Wrong endpoint: check that the DDNS name resolves to A's current IP, and that the ports match.
- Keys crossed incorrectly, or a preshared key set on only one side.
- Firewall: the A rule must target Device (input). Watch its counter in Status → Firewall while B tries to connect.
- Clock: if B rebooted with the wrong time, fix NTP and restart wg0 on A.
- Decisive test on A:
tcpdump -ni any udp port 51820. If nothing arrives, the problem is in the network path. If packets arrive but get no reply, it's the keys.
Handshake OK, but no traffic
- The remote LAN is missing from a peer's Allowed IPs, especially
192.168.14.0/24on A. - A tunnel address doesn't match the plan.
- Route Allowed IPs isn't checked.
- wg0 has no firewall zone, or sits in
wan.
Remote router answers, its servers don't
- Pinging
192.168.13.1only tests the router's input. Reaching servers needsvpn ⇒ lanforwarding. - The server's default gateway isn't the OpenWrt router, so replies go elsewhere.
- The server's host firewall drops foreign subnets. Windows blocks ICMP from other subnets by default.
- Run
sudo tcpdump -ni any icmpon the target: no request arriving means a router problem; a request without a reply means a host problem.
Site B lost internet
0.0.0.0/0is in a peer's Allowed IPs. Check Status → Routing for a default route on wg0.- The
lan ⇒ wanforwarding was removed while editing zones. - DNS points at a site A address. Check DHCP and DNS → Forwards and the interfaces' custom DNS fields.
- A local VPN client on the server is capturing its traffic (see above).
Adding a third site
For site C (192.168.15.0/24, tunnel IP 10.13.0.3):
- On A, add a peer with Allowed IPs
10.13.0.3/32and192.168.15.0/24. - On C, set Allowed IPs to
10.13.0.0/24and192.168.13.0/24, plus192.168.14.0/24if C should reach B through A. - On B, add
192.168.15.0/24to the existing site A peer. - A's
vpnzone already forwards vpn → vpn with Forward = accept, so A acts as the hub.
0.0.0.0/0. On the server side, add the client's LAN to its peer. Give wg0 its own firewall zone without masquerading, and leave the servers alone: their only gateway is the local router.