This is my little script for linux, you can free to modified.
#!/bin/sh
# Load Balance Script By: Andrie Johanes 04/01/2007 10:23 AM
# Free for distributed or modification
Name=balance
TABLE1=”speedy1″
TABLE2=”speedy2″
GW_ISP1=”192.168.10.1″
GW_ISP2=”192.168.20.1″
IP_ISP1=”192.168.10.2″
IP_ISP2=”192.168.20.2″
LAN=”192.168.15.0/24″
MARK_ISP1=”0xa”
MARK_ISP2=”0xb”
STOP() {
# DEL ROUTING DEFAULT TIAP TABLE
ip ro del default via $GW_ISP1 table $TABLE1
ip ro del default via $GW_ISP2 table $TABLE2
# DEL RULE ISP 1
ip ru del to $GW_ISP1 table $TABLE1
ip ru del from $IP_ISP1/32 table $TABLE1
# DEL RULE ISP 2
ip ru del to $GW_ISP2 table $TABLE2
ip ru del from $IP_ISP2/32 table $TABLE2
# DEL RULE DEFAULT TABLE UTAMA KERNEL
ip ru del from $GW_ISP1 table main
ip ru del to $IP_ISP1/32 table main
ip ru del from $GW_ISP2 table main
ip ru del to $IP_ISP2/32 table main
ip ru del to $LAN table main
# DEL PACKET MARK
ip ru del fwmark $MARK_ISP1 table $TABLE1
ip ru del fwmark $MARK_ISP2 table $TABLE2
ip ro flush cache
# STOP ROUTING LOAD BALANCE
ip ro del default nexthop via $GW_ISP1 weight 10 nexthop via $GW_ISP2 weight 10
ip ro add default via $GW_ISP1
}
START() {
# ADD ROUTING DEFAULT TIAP TABLE
ip ro add default via $GW_ISP1 table $TABLE1
ip ro add default via $GW_ISP2 table $TABLE2
# ADD RULE ISP 1
ip ru add to $GW_ISP1 table $TABLE1
ip ru add from $IP_ISP1/32 table $TABLE1
# ADD RULE ISP 2
ip ru add to $GW_ISP2 table $TABLE2
ip ru add from $IP_ISP2/32 table $TABLE2
# ADD RULE DEFAULT TABLE UTAMA KERNEL
ip ru add from $GW_ISP1 table main
ip ru add to $IP_ISP1/32 table main
ip ru add from $GW_ISP2 table main
ip ru add to $IP_ISP2/32 table main
ip ru add to $LAN table main
# ADD PACKET MARK
ip ru add fwmark $MARK_ISP1 table $TABLE1
ip ru add fwmark $MARK_ISP2 table $TABLE2
ip ro flush cache
ip ro del default
# START ROUTING LOAD BALANCE
ip ro add default nexthop via $GW_ISP1 weight 10 nexthop via $GW_ISP2 weight 10
}
case $1 in
start)
START
echo “Load Balance Start”
;;
stop)
STOP
echo “Load Balance Stop”
;;
restart)
STOP
START
echo “Load Balance Restart”
;;
*)
echo “*Usage /etc/init.d/$Name (start|stop|restart)”
esac
exit 0
