I have two network interfaces: wg0 and wg1 (wireguard). Via both of these, it is possible to reach (ipv6) address fc00:77ee::4, but wg1 can only reach the address if it is in a local network. the route via wg0 is going via a peer with the address fc00:77ee::1.
i want the route over wg1 to be chosen when available because it has lower latency. i am doing this by setting a lower metric for the route via wg1 than via wg0. but this makes contacting fc00:77ee::4 timeout when not in the local network. it refuses to use the other route when there is a timeout.
i made this script
ping -c 1 -W 2 fc00:77ee::4 -I wg1 &>/dev/null if [ $? -ne 0 ]; then sudo ip route del fc00:77ee::4 dev wg1 sudo ip route add fc00:77ee::4 metric 257 dev wg1 else ip route get fc00:77ee::4 dev wg1 | grep 'metric 255' if [ $? -ne 0 ]; then sudo ip route del fc00:77ee::4 dev wg1 sudo ip route add fc00:77ee::4 metric 255 dev wg1 fi fi
to change the metric to prefer the route via wg0 if the route via wg1 timeouts and this works quite well.
but is there any better way to do this? i.e. choose route via wg0 if route via wg1 timeouts and otherwise choose route via wg1? …because pinging the address every few seconds seems like a bad solution with a bunch of overhead.
am i missing something? is doing this via metric not the way?
is there some way to choose the least latency route via wireguard itself? i tried only having one wireguard interface with both peers and setting the endpoint of both, i.e. the peer with the address fc00:77ee::4 has an endpoint that is a local address, but this broke the connection to fc00:77ee::4 when not in the local network and did not result in it going via the other peer.