Really hope someone can help or at least tell my I'm out of my mind.
Each of openwrt router has 2x WAN ports, WANa (eth1), WANb (eth2), and 1x LAN port (eth5).
Using 2x vrrp_instances to monitor the 2x WAN interfaces respectively. Using ping 8.8.8.8 to detect the WAN port, if one of the WAN ports has a problem, switch "both" to the Backup and shutdown the LAN port(eth5).
MASTER:
cat /etc/keepalived/keepalived.conf
global_defs {
router_id HUAWEI1
}
vrrp_script check_wan {
script "/usr/bin/test $(ping -c 3 -I $INTERFACE 9.9.9.1 | grep 'received' | awk -F ',' '{print $2}' | awk '{print $1}') -eq 0 && ip link set eth5 down"
interval 10
weight 3
}
vrrp_sync_group BOX1 {
group {
WANa
WANb
}
}
vrrp_instance WANa {
state MASTER
interface eth1
virtual_router_id 51
priority 101
advert_int 1
virtual_ipaddress {
8.8.8.2
}
authentication {
auth_type PASS
auth_pass 1111
}
track_interface {
eth1
eth2
}
track_script {
check_wan {
interface eth1
}
}
}
vrrp_instance WANb {
state MASTER
interface eth2
virtual_router_id 51
priority 101
advert_int 1
virtual_ipaddress {
9.9.9.2
}
authentication {
auth_type PASS
auth_pass 1111
}
track_interface {
eth1
eth2
}
track_script {
check_wan {
interface eth2
}
}
}
BACKUP:
cat /etc/keepalived/keepalived.conf
global_defs {
router_id HUAWEI2
}
vrrp_script check_wan {
script "/usr/bin/test $(ping -c 3 -I $INTERFACE 9.9.9.1 | grep 'received' | awk -F ',' '{print $2}' | awk '{print $1}') -eq 0 && ip link set eth5 down"
interval 10
weight 3
}
vrrp_sync_group BOX2 {
group {
WANa
WANb
}
}
vrrp_instance WANa {
state BACKUP
interface eth1
virtual_router_id 51
priority 99
advert_int 1
virtual_ipaddress {
8.8.8.2
}
authentication {
auth_type PASS
auth_pass 1111
}
track_interface {
eth1
eth2
}
track_script {
check_wan {
interface eth1
}
}
}
vrrp_instance WANb {
state BACKUP
interface eth2
virtual_router_id 51
priority 99
advert_int 1
virtual_ipaddress {
9.9.9.2
}
authentication {
auth_type PASS
auth_pass 1111
}
track_interface {
eth1
eth2
}
track_script {
check_wan {
interface eth2
}
}
}
Problem 1:
script "/usr/bin/test $(ping -c 3 -I $INTERFACE 8.8.8.8 | grep 'received' | awk -F ',' '{print $2}' | awk '{print $1}') -eq 0 && ip link set eth5 down" works when tested on the command line. When ping to 9.9.9.1 is not reachable, it will shutdown eth5. For example: /usr/bin/test $(ping -c 3 -I eth1 9.9.9.1 | grep 'received' | awk -F ',' '{print $2}' | awk '{print $1}') -eq 0 && ip link set eth5 down
However, when this command is put into keepalived.conf with script "", it does not work and eth5 will not be shut down.
Problem 2:
When ping 9.9.9.1 is not reachable, I did not see the two WAN ports switch to the backup. When I enter "ip a" on the MASTER, I can still see the virtual IP addresses: 8.8.8.2 and 9.9.9.2 as below:
root@OpenWrt:~# ip a
...
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:90:27:e7:17:02 brd ff:ff:ff:ff:ff:ff
inet 8.8.8.8/24 brd 8.8.8.255 scope global eth1
valid_lft forever preferred_lft forever
inet 8.8.8.2/32 scope global eth1
valid_lft forever preferred_lft forever
inet6 fe80::290:27ff:fee7:1702/64 scope link
valid_lft forever preferred_lft forever
4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:90:27:e7:17:03 brd ff:ff:ff:ff:ff:ff
inet 9.9.9.8/24 brd 9.9.9.255 scope global eth2
valid_lft forever preferred_lft forever
inet 9.9.9.2/32 scope global eth2
valid_lft forever preferred_lft forever
inet6 fe80::290:27ff:fee7:1703/64 scope link
valid_lft forever preferred_lft forever
5: eth3: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc mq master bond-lag1 state UP group default qlen 1000
link/ether 00:90:27:e7:17:04 brd ff:ff:ff:ff:ff:ff
6: eth4: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc mq master bond-lag1 state UP group default qlen 1000
link/ether 00:90:27:e7:17:04 brd ff:ff:ff:ff:ff:ff permaddr 00:90:27:e7:17:05
7: eth5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master br-lan state UP group default qlen 1000
link/ether 00:90:27:e7:17:06 brd ff:ff:ff:ff:ff:ff
...