The main problem is that Wireguard interfaces are in UP state even though no real connection to the remote site is established. For example if you disble link on cloud1, vyos node wg0 interface will be in up state…
How about use bgp for load balancing and failover?
Cloud1 and Cloud2 use bgp for connection with node “vyos” via wireguard interfaces. Each cloud export “default originate” route to “vyos”
VyOS places these routes to table 100.
One problem, that we don’t have a native cli for placing prefixes to route-table 100. So we need some tricks yet.
Configuration “vyos”:
set interfaces ethernet eth0 address '100.64.0.2/30'
set interfaces ethernet eth1 address '192.168.2.1/24'
set interfaces ethernet eth1 policy route 'PBR'
set interfaces wireguard wg0 address '10.10.10.254/24'
set interfaces wireguard wg0 description 'Server-CLOUD1-203.0.113.254'
set interfaces wireguard wg0 peer CLOUD1 allowed-ips '10.10.10.0/24'
set interfaces wireguard wg0 peer CLOUD1 allowed-ips '0.0.0.0/0'
set interfaces wireguard wg0 peer CLOUD1 endpoint '203.0.113.254:64216'
set interfaces wireguard wg0 peer CLOUD1 pubkey 'xx='
set interfaces wireguard wg1 address '10.20.20.254/24'
set interfaces wireguard wg1 description 'Server-CLOUD2-198.51.100.254'
set interfaces wireguard wg1 peer CLOUD2 allowed-ips '10.20.20.0/24'
set interfaces wireguard wg1 peer CLOUD2 allowed-ips '0.0.0.0/0'
set interfaces wireguard wg1 peer CLOUD2 endpoint '198.51.100.254:64216'
set interfaces wireguard wg1 peer CLOUD2 pubkey 'xx='
set nat source rule 100 outbound-interface 'wg0'
set nat source rule 100 source address '192.168.2.0/24'
set nat source rule 100 translation address 'masquerade'
set nat source rule 110 outbound-interface 'wg1'
set nat source rule 110 source address '192.168.2.0/24'
set nat source rule 110 translation address 'masquerade'
set policy route PBR rule 10 destination address '!192.168.2.0/24'
set policy route PBR rule 10 set table '100'
set policy route PBR rule 10 source address '192.168.2.0/24'
set protocols bgp 65001 maximum-paths ibgp '2'
set protocols bgp 65001 neighbor 10.10.10.1 remote-as '65001'
set protocols bgp 65001 neighbor 10.10.10.1 timers holdtime '30'
set protocols bgp 65001 neighbor 10.10.10.1 timers keepalive '10'
set protocols bgp 65001 neighbor 10.10.10.1 update-source '10.10.10.254'
set protocols bgp 65001 neighbor 10.20.20.1 remote-as '65001'
set protocols bgp 65001 neighbor 10.20.20.1 timers holdtime '30'
set protocols bgp 65001 neighbor 10.20.20.1 timers keepalive '10'
set protocols bgp 65001 neighbor 10.20.20.1 update-source '10.20.20.254'
set protocols static interface-route 10.10.10.0/24 next-hop-interface wg0
set protocols static interface-route 10.20.20.0/24 next-hop-interface wg1
set protocols static route 198.51.100.254/32 next-hop 100.64.0.1
set protocols static route 203.0.113.254/32 next-hop 100.64.0.1
Additional tricks:
sudo vtysh -c "conf t" -c "route-map RMAP-IN permit 100" -c " set table 100"
sudo vtysh -c "conf t" -c "router bgp 65001" -c "address-family ipv4 unicast" -c "neighbor 10.10.10.1 route-map RMAP-IN in" -c "neighbor 10.20.20.1 route-map RMAP-IN in"
So we receive 2 default routes from neighbors
vyos@vyos:~$ show ip bgp sum
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
10.10.10.1 4 65001 148 155 0 0 0 00:13:31 1
10.20.20.1 4 65001 71 70 0 0 0 01:00:56 1
And these routes exported to table 100
vyos@vyos:~$ show ip route table 100
VRF default table 100:
B>* 0.0.0.0/0 [200/0] via 10.10.10.1, wg0, 00:00:10
* via 10.20.20.1, wg1, 00:00:10
vyos@vyos:~$
I reduced the timers, for a faster response of the bgp states.
Feature request for “set table x” in route-maps ⚓ T3032 Ability to "set table" in the policy route-map