I am presumimg that both lines are used (load balance) and that if one goes down the other will take the complete load until the down line comes up again. Then you load balance once more.if the cable line goes down, the traffic will be directed to the DSL line that is up until the main line comes back online and then traffic goes back to the cable line.
#!/bin/sh
. /etc/coyote/coyote.conf
. /tmp/netsubsys.state
[ -z "$PING_IP" ] && PING_IP=72.14.205.103
[ -z "$PING_RETRY" ] && PING_RETRY=3
ping=/usr/sbin/ping
ERR=0
CHECK1=0
CHECK2=0
CHECK3=0
CHECK4=0
if [ "$INET_UP" = "UP" ] ; then
if [ "$INETTYPE" = "PPP" -o "$INETTYPE" = "PPPOE" ] ; then
IF_INET=ppp0
IPADDR=`getifaddr $IF_INET`
GATEWAY=`ifconfig ppp0 | grep P-t-P`
GATEWAY=`echo $GATEWAY | cut -f 3 -d " "`
GATEWAY=`echo $GATEWAY | cut -f 2 -d :`
elif [ "$INETTYPE" = "ETHERNET_DHCP" ] ; then
. /etc/dhcpc/$IF_INET.info
IPADDR=$dhcp_ip
GATEWAY=$dhcp_router
fi
fi
check_ping() {
COUNT=1
while [ $COUNT -le $PING_RETRY ]; do
$ping -c 1 -I $1 "$PING_IP" > /dev/null
[ $? = 0 ] && return 0 || { COUNT=$(($COUNT+1)); }
done
return 1
}
flush_cache() {
if [ "$LOAD_BALANCE" = "YES" ] ; then
COMMAND="ip ro add default table 222 proto static"
[ $CHECK1 = 0 ] && COMMAND=$COMMAND" nexthop via $GATEWAY dev $IF_INET weight $INET_WEIGHT"
[ $CHECK2 = 0 ] && COMMAND=$COMMAND" nexthop via $INET2_GATEWAY dev $IF_INET2 weight $INET2_WEIGHT"
[ $CHECK3 = 0 ] && COMMAND=$COMMAND" nexthop via $INET3_GATEWAY dev $IF_INET3 weight $INET3_WEIGHT"
[ $CHECK4 = 0 ] && COMMAND=$COMMAND" nexthop via $INET4_GATEWAY dev $IF_INET4 weight $INET4_WEIGHT"
ip ro flush table 222
ip ro flush cache
$COMMAND
fi
}
while [ /bin/true ]; do
[ ! -z $IF_INET ] && { OLD_CHECK1=$CHECK1;
check_ping $IPADDR && CHECK1=0 || CHECK1=1;
[ $CHECK1 != $OLD_CHECK1 ] && ERR=1; }
[ ! -z $IF_INET2 ] && { OLD_CHECK2=$CHECK2;
check_ping $INET2_IPADDR && CHECK2=0 || CHECK2=1;
[ $CHECK2 != $OLD_CHECK2 ] && ERR=1; }
[ ! -z $IF_INET3 ] && { OLD_CHECK3=$CHECK3;
check_ping $INET3_IPADDR && CHECK3=0 || CHECK3=1;
[ $CHECK3 != $OLD_CHECK3 ] && ERR=1; }
[ ! -z $IF_INET4 ] && { OLD_CHECK4=$CHECK4;
check_ping $INET4_IPADDR && CHECK4=0 || CHECK4=1;
[ $CHECK4 != $OLD_CHECK4 ] && ERR=1; }
[ $ERR -gt 0 ] && flush_cache
sleep 50
done
CODE REMOVED see the latest in my post below
That is not how I thought load balancing worked. According to the docs it is supposed to send traffic through both. What you describe is load balancing that does not work. If this is the case then I ask the question why is it there?I have two links, one 8Mbit/8Mbib and second 2Mbit/256Kbit DSL. Set weight for first link to 4 and for second link for 1. After i turn on the LoadBalancing, all my traffic is redirected to DS
RX bytes:2572141 (2.4 MiB) TX bytes:280679 (274.1 KiB)
- when first link is active, then all traffik goes through it
- when first link is dead, then all trafik is redirected to second link
- after the first link is again alive, all traffik goes through it
#!/bin/sh
. /etc/coyote/coyote.conf
. /tmp/netsubsys.state
while true ; do
GW="0.0.0.0"
if [ "$INET_UP" = "UP" ] ; then
if [ "$INETTYPE" = "PPP" -o "$INETTYPE" = "PPPOE" ] ; then
IF_INET=ppp0
GATEWAY=`ifconfig ppp0 | grep P-t-P`
GATEWAY=`echo $GATEWAY | cut -f 3 -d " "`
GATEWAY=`echo $GATEWAY | cut -f 2 -d :`
elif [ "$INETTYPE" = "ETHERNET_DHCP" ] ; then
. /etc/dhcpc/$IF_INET.info
GATEWAY=$dhcp_router
fi
GW=$GATEWAY
fi
ping -c 1 $GW
[ -n "$INET2_GATEWAY" ] && ping -c 1 $INET2_GATEWAY
[ -n "$INET3_GATEWAY" ] && ping -c 1 $INET3_GATEWAY
[ -n "$INET4_GATEWAY" ] && ping -c 1 $INET4_GATEWAY
sleep 50
done
#!/bin/sh
. /etc/coyote/coyote.conf
. /tmp/netsubsys.state
#. /etc/failover.conf
ACTIVE='YES'
PING_IP1='209.85.193.147'
PING_IP2='209.85.193.147'
PING_IP3='209.85.193.147'
PING_IP4='209.85.193.147'
COUNT='5'
test "$ACTIVE" = "NO" && exit
##########################
# Configure variables
##########################
# Debug -> if debug = 1, log the commands and the command result in the FILE
DEBUG=1
# FILE -> the debug file
LOG="/partition/linecheck.log"
# TABLE number -> this should be greped in /etc/rc.d/rc.loadbalance
TABLE=222
# CORRECTED -> if th gateways was corrected
CORRECTED=0
# LASTATE -> last state os the links
LASTATE=0
# GWNO -> number of gateways
GWNO=0
# SECONDS -> seconds to sleep until check the lines again
SECONDS=10
log(){
if [ $DEBUG = 0 ] ; then
return;
fi
# Actual time
TIME=$(date +%X)
#Date dd/mm/yyyy
TODAY=$(date +%d/%b/%Y)
echo "${TODAY}, $TIME - ${1} " >> $LOG
# echo "${TODAY}, $TIME - ${1} "
}
log "Staring linecheck"
# Change default interface name from eth1 to ppp0 if using PPPoE
if [ "$INETTYPE" = "PPP" -o "$INETTYPE" = "PPPOE" ] ; then
IF_INET=ppp0
fi
[ $IF_INET ] && GATEWAY1=`ip route list table $TABLE | grep $IF_INET | cut -d " " -f 3`
[ $IF_INET ] && log "Gateway 1: $GATEWAY1"
[ $IF_INET2 ] && GATEWAY2=`ip route list table $TABLE | grep $IF_INET2 | cut -d " " -f 3`
[ $IF_INET2 ] && log "Gateway 2: $GATEWAY2"
[ $IF_INET3 ] && GATEWAY3=`ip route list table $TABLE | grep $IF_INET3 | cut -d " " -f 3`
[ $IF_INET3 ] && log "Gateway 3: $GATEWAY3"
[ $IF_INET4 ] && GATEWAY4=`ip route list table $TABLE | grep $IF_INET4 | cut -d " " -f 3`
[ $IF_INET4 ] && log "Gateway 4: $GATEWAY4"
[ $GATEWAY1 ] && GWNO=$(($GWNO + 1))
[ $GATEWAY2 ] && GWNO=$(($GWNO + 1))
[ $GATEWAY3 ] && GWNO=$(($GWNO + 1))
[ $GATEWAY4 ] && GWNO=$(($GWNO + 1))
log "Number of gateways: $GWNO"
[ $IF_INET ] && NETMASK1=`ifconfig $IF_INET | grep Mask | cut -d ":" -f 4 | cut -d " " -f 0`
[ $IF_INET ] && log "Netmask 1: $NETMASK1"
[ $IF_INET2 ] && NETMASK2=`ifconfig $IF_INET2 | grep Mask | cut -d ":" -f 4 | cut -d " " -f 0`
[ $IF_INET2 ] && log "Netmask 2: $NETMASK2"
[ $IF_INET3 ] && NETMASK3=`ifconfig $IF_INET3 | grep Mask | cut -d ":" -f 4 | cut -d " " -f 0`
[ $IF_INET3 ] && log "Netmask 3: $NETMASK3"
[ $IF_INET4 ] && NETMASK4=`ifconfig $IF_INET4 | grep Mask | cut -d ":" -f 4 | cut -d " " -f 0`
[ $IF_INET4 ] && log "Netmask 4: $NETMASK4"
[ $IF_INET ] && INET_IP1=`ifconfig $IF_INET | grep "inet addr" | cut -d ":" -f 2 | cut -d " " -f 0`
[ $IF_INET ] && log "INET_IP1: $INET_IP1"
[ $IF_INET2 ] && INET_IP2=`ifconfig $IF_INET2 | grep "inet addr" | cut -d ":" -f 2 | cut -d " " -f 0`
[ $IF_INET2 ] && log "INET_IP2: $INET_IP2"
[ $IF_INET3 ] && INET_IP3=`ifconfig $IF_INET3 | grep "inet addr" | cut -d ":" -f 2 | cut -d " " -f 0`
[ $IF_INET3 ] && log "INET_IP3: $INET_IP3"
[ $IF_INET4 ] && INET_IP4=`ifconfig $IF_INET4 | grep "inet addr" | cut -d ":" -f 2 | cut -d " " -f 0`
[ $IF_INET4 ] && log "INET_IP4: $INET_IP4"
echo "IF_INET='"$IF_INET"'" > /tmp/failover.info
echo "INET_IP1='"$INET_IP1"'" >> /tmp/failover.info
echo "NETMASK1='"$NETMASK1"'" >> /tmp/failover.info
echo "GATEWAY1='"$GATEWAY1"'" >> /tmp/failover.info
echo "INET_WEIGHT='"$INET_WEIGHT"'" >> /tmp/failover.info
echo "IF_INET2='"$IF_INET2"'" >> /tmp/failover.info
echo "INET_IP2='"$INET_IP2"'" >> /tmp/failover.info
echo "NETMASK2='"$NETMASK2"'" >> /tmp/failover.info
echo "GATEWAY2='"$GATEWAY2"'" >> /tmp/failover.info
echo "INET2_WEIGHT='"$INET2_WEIGHT"'" >> /tmp/failover.info
echo "IF_INET3='"$IF_INET3"'" >> /tmp/failover.info
echo "INET_IP3='"$INET_IP3"'" >> /tmp/failover.info
echo "NETMASK3='"$NETMASK3"'" >> /tmp/failover.info
echo "GATEWAY3='"$GATEWAY3"'" >> /tmp/failover.info
echo "INET3_WEIGHT='"$INET3_WEIGHT"'" >> /tmp/failover.info
echo "IF_INET4='"$IF_INET4"'" >> /tmp/failover.info
echo "INET_IP4='"$INET_IP4"'" >> /tmp/failover.info
echo "NETMASK4='"$NETMASK4"'" >> /tmp/failover.info
echo "GATEWAY4='"$GATEWAY4"'" >> /tmp/failover.info
echo "INET4_WEIGHT='"$INET4_WEIGHT"'" >> /tmp/failover.info
# Start daemon
while [ /bin/true ] ; do
GW_OK=0
FAIL=0
CHECK1=0
CHECK2=0
CHECK3=0
CHECK4=0
if [ $GATEWAY1 ] ; then
ping2 -c $COUNT -I $IF_INET $PING_IP1 > /dev/null
CHECK1=`echo $?`
log "Check1: $CHECK1"
fi
if [ $GATEWAY2 ] ; then
ping2 -c $COUNT -I $IF_INET2 $PING_IP2 > /dev/null
CHECK2=`echo $?`
log "Check2: $CHECK2"
fi
if [ $GATEWAY3 ] ; then
ping2 -c $COUNT -I $IF_INET3 $PING_IP3 > /dev/null
CHECK3=`echo $?`
log "Check3: $CHECK3"
fi
if [ $GATEWAY4 ] ; then
ping2 -c $COUNT -I $IF_INET4 $PING_IP4 > /dev/null
CHECK4=`echo $?`
log "Check4: $CHECK4"
fi
echo "CHECK1='"$CHECK1"'" > /tmp/failover.status
echo "CHECK2='"$CHECK2"'" >> /tmp/failover.status
echo "CHECK3='"$CHECK3"'" >> /tmp/failover.status
echo "CHECK4='"$CHECK4"'" >> /tmp/failover.status
FAIL=$(($CHECK1+$CHECK2+$CHECK3+$CHECK4))
# log "Fail: $FAIL"
# If FAIL > 0 and no corrected, fix the table
if [ $FAIL != 0 ] ; then
log "Fail: $FAIL"
if [ $CORRECTED = 0 ] || [ $LASTATE != $FAIL ] ; then
COMMAND="ip route add default table $TABLE proto static"
[ $GATEWAY1 ] && [ $CHECK1 = 0 ] && COMMAND=$COMMAND" nexthop via $GATEWAY1 dev $IF_INET weight $INET_WEIGHT"
[ $GATEWAY2 ] && [ $CHECK2 = 0 ] && COMMAND=$COMMAND" nexthop via $GATEWAY2 dev $IF_INET2 weight $INET2_WEIGHT"
[ $GATEWAY3 ] && [ $CHECK3 = 0 ] && COMMAND=$COMMAND" nexthop via $GATEWAY3 dev $IF_INET3 weight $INET3_WEIGHT"
[ $GATEWAY4 ] && [ $CHECK4 = 0 ] && COMMAND=$COMMAND" nexthop via $GATEWAY4 dev $IF_INET4 weight $INET4_WEIGHT"
log "Command: $COMMAND"
ip route flush table $TABLE
ip route flush cache
$COMMAND
log "ip route flush table $TABLE"
log "ip route flush cache"
CORRECTED=1
LASTATE=$FAIL
log "Corrected: $CORRECTED"
log "Last state: $LASTATE"
fi
else
# If no FAIL, try to restore the failed WAN
GW_OK=`ip route list table $TABLE | grep -c via`
#log "Working gateways: $GW_OK of $GWNO"
if [ $GW_OK != $GWNO ] ; then
log "Working gateways: $GW_OK of $GWNO"
COMMAND="ip route add default table $TABLE proto static"
[ $GATEWAY1 ] && [ $CHECK1 = 0 ] && COMMAND=$COMMAND" nexthop via $GATEWAY1 dev $IF_INET weight $INET_WEIGHT"
[ $GATEWAY2 ] && [ $CHECK2 = 0 ] && COMMAND=$COMMAND" nexthop via $GATEWAY2 dev $IF_INET2 weight $INET2_WEIGHT"
[ $GATEWAY3 ] && [ $CHECK3 = 0 ] && COMMAND=$COMMAND" nexthop via $GATEWAY3 dev $IF_INET3 weight $INET3_WEIGHT"
[ $GATEWAY4 ] && [ $CHECK4 = 0 ] && COMMAND=$COMMAND" nexthop via $GATEWAY4 dev $IF_INET4 weight $INET4_WEIGHT"
ip route flush table $TABLE
ip route flush cache
$COMMAND
log "ip route flush table $TABLE"
log "ip route flush cache"
log "Command: $COMMAND"
CORRECTED=0
log "Corrected: $CORRECTED"
fi
fi
sleep $SECONDS
done
#!/bin/sh
. /etc/coyote/coyote.conf
#Take the (error) state of all lines.
#INET1,2,3,4 are states 1,2,4,8 respectively
state=0
#a count of 1 is not a good indicator for a line down
COUNT="-c 5"
INTERVAL="-i 5"
#first time only - presuming prev_state is all lines up
if ! [ -e /tmp/loadbalance.state ]; then
echo 0 > /tmp/loadbalance.state
fi
case "$INETTYPE" in
"PPPOE" | "PPP" )
if [ -n "ppp0" ]; then
IF_INET=ppp0
IPADDR=`getifaddr ppp0`
GATEWAY=`ifconfig ppp0 | grep P-t-P | cut -f 3 -d ':' | cut -f 1 -d ' '`
fi
;;
"ETHERNET_DHCP" )
if [ -e "/etc/dhcpc/$IF_INET.info" ]; then
. /etc/dhcpc/$IF_INET.info
IPADDR=$dhcp_ip
GATEWAY=$dhcp_router
fi
;;
esac
if [ -n "IPADDR" ] && [ -n "$IF_INET" ]; then
#echo testing First External Interface
loss=`ping $COUNT $INTERVAL $GATEWAY | grep received | cut -d ' ' -f 6`
if [ "$loss" = "100%" ]; then
logger $GATEWAY is down
state=1
else
[ -z $INET_WEIGHT ] && INET_WEIGHT=1
route1="nexthop via $GATEWAY dev $IF_INET weight $INET_WEIGHT"
fi
fi
if [ -n "$INET2_IPADDR" ] && [ -n "$IF_INET2" ]; then
#echo testing Second External Interface
loss=`ping $COUNT $INTERVAL $INET2_GATEWAY | grep received | cut -d ' ' -f 6`
if [ "$loss" = "100%" ]; then
logger $INET2_GATEWAY is down
state=$((state+2))
else
[ -z $INET2_WEIGHT ] && INET2_WEIGHT=1
route2="nexthop via $INET2_GATEWAY dev $IF_INET2 weight $INET2_WEIGHT"
fi
fi
if [ -n "$INET3_IPADDR" ] && [ -n "$IF_INET3" ]; then
#echo testing Third external interface
loss=`ping $COUNT $INTERVAL $INET3_GATEWAY | grep received | cut -d ' ' -f 6`
if [ "$loss" = "100%" ]; then
logger $INET3_GATEWAY is down
state=$((state+4))
else
[ -z $INET3_WEIGHT ] && INET3_WEIGHT=1
route3="nexthop via $INET3_GATEWAY dev $IF_INET3 weight $INET3_WEIGHT"
fi
fi
if [ -n "$INET4_IPADDR" ] && [ -n "$IF_INET4" ]; then
#echo testing Fourth external interface
loss=`ping $COUNT $INTERVAL $INET4_GATEWAY | grep received | cut -d ' ' -f 6`
if [ "$loss" = "100%" ]; then
logger $INET4_GATEWAY is down
state=$((state+8))
else
[ -z $INET4_WEIGHT ] && INET4_WEIGHT=1
route4="nexthop via $INET4_GATEWAY dev $IF_INET4 weight $INET4_WEIGHT"
fi
fi
prev_state=`cat /tmp/loadbalance.state`
if ! [ $state = $prev_state ]; then
logger configuring new route table 222
ip route flush table 222
ip route flush cache
ip route add default table 222 proto static $route1 $route2 $route3 $route4
echo $state > /tmp/loadbalance.state
logger loadbalance error state changed from $prev_state to $state
fi
My testing consisted of 3 WAN NICS on BFW going to a hub with one workstation that had 3 IPs assigned to one NIC (simulating 3 gateways).
I don't have that (4 modems) Do a lot of people do it like that? 4 ISPs on I NIC? I really only have one ISP.In my test I put 1 WAN NIC that had 4 IPs assigned on BFW going to a hub with 4 DSL modems.
True. If the ISP changed the router at his end that would cause problems (for a lot of people). I'll try to test that and see.but without MAC testing
yeager escreveu:Is it possible to use this skript without LoadBalancing? So i will use in same time only one link, and when is dead, then switche to the second link.
Is that second link up all the time also?So i will use in same time only one link, and when is dead, then switche to the second link.
Voltar para BrazilFW 2.x - English Forum
Usuários navegando neste fórum: Nenhum usuário registrado e 1 visitante