It's do-able without external tools or complicated routing protocol setup.
We assume that the LAN subnet behind router 1, to be accessible from router 2 is 192.168.10.0/24. And the LAN subnet behind router 2, to be accessible from router 1 is 192.168.20.0/24.
On each of the two routers, add a separate WireGuard interface (let's say wg1) with the subnet, for example 10.0.10.0/24.
- Router 1 has WG address
10.0.10.100/24 on its wg1.
- Router 2 has WG address
10.0.10.200/24 on its wg1.
- Router 1 has direct WG peer to router 2 on
wg1, with allowed-address=10.0.10.200/32,192.168.20.0/24.
- Router 2 has direct WG peer to router 1 on
wg1, with allowed-address=10.0.10.100/32,192.168.10.0/24.
On each of the two routers, configure a 2nd WireGuard interface (let's say wg2), listening on different UDP port from the one of wg1, of course. This interface is for the communication with the VPS. The used subnet is for example 10.0.20.0/24.
- Router 1 has WG address
10.0.20.100/24 on its wg2.
- Router 2 has WG address
10.0.20.200/24 on its wg2.
- Router 1 has WG peer to VPS on
wg2, with allowed-address=10.0.10.0/24,192.168.20.0/24.
- Router 2 has WG peer to VPS on
wg2, with allowed-address=10.0.10.0/24,192.168.10.0/24.
On VPS router:
- VPS has WG address
Address = 10.0.20.1/32 under [Interface].
- In the
[Peer] setting towards router 1, set AllowedIPs = 10.0.20.100/32, 192.168.10.0/24.
- In the
[Peer] setting towards router 2, set AllowedIPs = 10.0.20.200/32, 192.168.20.0/24.
- Assuming tools like
wg-quick is used, corresponding routes should be automatically installed.
- Make sure forwarding is enabled (
net.ipv4.ip_forward=1).
On router 1, we add routes towards the router 2's LAN subnet 192.168.20.0/24. The route with lower distance uses the direct WG link to router 2. The failover route uses the WG link to VPS.
/ip route
add dst-address=192.168.20.0/24 check-gateway=ping gateway=10.0.10.200 distance=1
add dst-address=192.168.20.0/24 check-gateway=ping gateway=10.0.20.200 distance=2
On router 2, we add routes towards the router 1's LAN subnet 192.168.10.0/24. The route with lower distance uses the direct WG link to router 1. The failover route uses the WG link to VPS.
/ip route
add dst-address=192.168.10.0/24 check-gateway=ping gateway=10.0.10.100 distance=1
add dst-address=192.168.10.0/24 check-gateway=ping gateway=10.0.20.100 distance=2
Make sure the firewall on all three devices allows forwarding between the relevant subnets.
With the configuration, when the WG link (interface wg1) between the two routers in working, and they can ping themselves through it, then the traffic between the two LAN subnets will use this link. If it's down, the link through the VPS will be used.
Same principle applies if the two LAN subnets use IPv6. You can use fixed ULA addresses for the WG interfaces in place of the 10.0.x.y ones.