The document https://docs.vyos.io/en/1.5/configuration/loadbalancing/wan.html states that there are two environment variables available for scripts. However, I tried using WLB_INTERFACE_NAME in a script and the script read WLB_INTERFACE_NAME as blank.
The document indicates that you only need to provide the full path if the script is not in /config/scripts, however, if you only provide the name it errors stating the script does not exist even though it is in /config/scripts.
Ping tests fail on interfaces that are not the selected default gateway. An oder version of the document provided above states that static routes should be provided for the targets. This is an issue because it means that when the interface for the static route is down no device can reach that IP though it's available through another interface. A solution is to setup local route policies for each WAN interface. This ensures that if the source specified is the the IP on that WAN it the traffic will leave that gateway.
set protocols static table 102 route 0.0.0.0/0 dhcp-interface bond0.102 set policy local-route rule 102 source address 192.168.1.0/24 set policy local-route rule 102 set table 102
There are two issues with this setup.
- There is no option to select the interface IP or subnet for the source address from DHCP like you can set the next-hop to use the dhcp interfaces provided next-hop.
- The ping tests for wan load balance do not set the source IP for the interface being tested. I created the following script and have a copy for each wan interface to run the ping sourcing the dhcp assigned IP. If the ping tests fails it also releases and renews the DHCP lease. This is a good option to have for DHCP interfaces outside of wan load balancing where issues can arise that will not bounce the port on VyOS router so detection needs to happen another way.
#!/bin/bash WLB_INTERFACE_NAME='bond0.101' WLB_ICMP_COUNT='4' WLB_TEST_HOSTS=(1.0.0.1 1.1.1.1 4.2.2.1 4.2.2.2 4.2.2.3 4.2.2.4 8.8.4.4 8.8.8.8) WLB_INTERFACE_IP="$(ip -4 addr show dev "${WLB_INTERFACE_NAME}" | awk '$1 == "inet" && $2 ~ /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\/([0-9]|[12][0-9]|3[0-2])$/ && /dynamic/ {print $2}' | cut -d/ -f1 | head -1)" WLB_TESTS_FUN () { WLB_TEST_HOST_ICMP_EXIT_CODES=() if [ "${#WLB_TEST_HOSTS[@]}" -gt '0' ] then for WLB_TEST_HOST in ${WLB_TEST_HOSTS[@]} do /usr/bin/ping -q ${WLB_TEST_HOST} -I ${WLB_INTERFACE_IP} -c ${WLB_ICMP_COUNT} WLB_TEST_HOST_ICMP_EXIT_CODE="$?" if [ "${WLB_TEST_HOST_ICMP_EXIT_CODE}" -gt '0' ] then WLB_TEST_HOST_ICMP_EXIT_CODES=(${WLB_TEST_HOST_ICMP_EXIT_CODES[@]} ${WLB_TEST_HOST_ICMP_EXIT_CODE}) fi done fi } WLB_TESTS_FUN if [ "${#WLB_TEST_HOSTS[@]}" -gt "${#WLB_TEST_HOST_ICMP_EXIT_CODES[@]}" ] then sleep 10 exit 0 else # Release the current DHCP lease. /sbin/dhclient -r "${WLB_INTERFACE_NAME}" sleep 5 # Request a new DHCP lease. /sbin/dhclient "${WLB_INTERFACE_NAME}" sleep 15 # DHCP may have assigned a different address, so refresh it. WLB_INTERFACE_IP="$(ip -4 addr show dev "${WLB_INTERFACE_NAME}" | awk '$1 == "inet" && $2 ~ /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\/([0-9]|[12][0-9]|3[0-2])$/ && /dynamic/ {print $2}' | cut -d/ -f1 | head -1)" # Test again using the renewed DHCP address. WLB_TESTS_FUN fi sleep 10 if [ "${#WLB_TEST_HOSTS[@]}" -gt "${#WLB_TEST_HOST_ICMP_EXIT_CODES[@]}" ] then exit 0 else exit 1 fi