2
« เมื่อ: 21 กรกฎาคม 2008, 02:27:12 »
แล้วถ้า 4 wan 2 game 2 net net ทำ loadbalance กัน
เขียนแบบนี้ใช้งานได้ไหมครับ ชี้แนะด้วย
#!/bin/sh
oldstatus=0
while [ 1 ]
do
status=0
ppp101=`/sbin/ifconfig -a | grep "ppp101"`
if [ -n "$ppp101" ]; then
# echo "ppp101 is up"
status=`expr $status + 1`
fi
ppp102=`/sbin/ifconfig -a | grep "ppp102"`
if [ -n "$ppp102" ]; then
# echo "ppp102 is up"
status=`expr $status + 2`
fi
ppp103=`/sbin/ifconfig -a | grep "ppp103"`
if [ -n "$ppp103" ]; then
# echo "ppp103 is up"
status=`expr $status + 4`
fi
ppp104=`/sbin/ifconfig -a | grep "ppp104"`
if [ -n "$ppp104" ]; then
# echo "ppp104 is up"
status=`expr $status + 8`
fi
if [ $status != $oldstatus ]; then
#/etc/ppp/ip-up.d/0route
if $status = 0 then
elif $status = 1 then
#use line 1
ppp101=`/sbin/ifconfig -a | grep "ppp101"`
# echo "ppp101 is up"
ip route add default table 101 dev ppp101
ip route add default table 201 dev ppp101
IPWAN=`ip addr show ppp101 |grep inet |cut -d " " -f 6`
ip rule del prio 201
ip rule add from $IPWAN lookup 201 prio 201
elif $status = 2 then
#use line 2
ppp102=`/sbin/ifconfig -a | grep "ppp102"`
# echo "ppp102 is up"
ip route add default table 102 dev ppp102
ip route add default table 202 dev ppp102
IPWAN=`ip addr show ppp102 |grep inet |cut -d " " -f 6`
ip rule del prio 202
ip rule add from $IPWAN lookup 202 prio 202
elif $status = 3 then
#use line 12
ppp101=`/sbin/ifconfig -a | grep "ppp101"`
# echo "ppp101 is up"
ip route add default table 101 dev ppp101
ip route add default table 201 dev ppp101
IPWAN=`ip addr show ppp101 |grep inet |cut -d " " -f 6`
ip rule del prio 201
ip rule add from $IPWAN lookup 201 prio 201
ppp102=`/sbin/ifconfig -a | grep "ppp102"`
# echo "ppp102 is up"
ip route add default table 102 dev ppp102
ip route add default table 202 dev ppp102
IPWAN=`ip addr show ppp102 |grep inet |cut -d " " -f 6`
ip rule del prio 202
ip rule add from $IPWAN lookup 202 prio 202
elif $status = 4 then
#use line 3
ppp103=`/sbin/ifconfig -a | grep "ppp103"`
# echo "ppp103 is up"
ip route add default table 103 dev ppp103
ip route add default table 203 dev ppp103
IPWAN=`ip addr show ppp103 |grep inet |cut -d " " -f 6`
ip rule del prio 203
ip rule add from $IPWAN lookup 203 prio 203
elif $status = 5 then
#use line 13
ppp101=`/sbin/ifconfig -a | grep "ppp101"`
# echo "ppp101 is up"
ip route add default table 101 dev ppp101
ip route add default table 201 dev ppp101
IPWAN=`ip addr show ppp101 |grep inet |cut -d " " -f 6`
ip rule del prio 201
ip rule add from $IPWAN lookup 201 prio 201
ppp103=`/sbin/ifconfig -a | grep "ppp103"`
# echo "ppp103 is up"
ip route add default table 103 dev ppp103
ip route add default table 203 dev ppp103
IPWAN=`ip addr show ppp103 |grep inet |cut -d " " -f 6`
ip rule del prio 203
ip rule add from $IPWAN lookup 203 prio 203
elif $status = 6 then
#use line 2 and 3
ppp102=`/sbin/ifconfig -a | grep "ppp102"`
# echo "ppp102 is up"
ip route add default table 102 dev ppp102
ip route add default table 202 dev ppp102
IPWAN=`ip addr show ppp102 |grep inet |cut -d " " -f 6`
ip rule del prio 202
ip rule add from $IPWAN lookup 202 prio 202
ppp103=`/sbin/ifconfig -a | grep "ppp103"`
# echo "ppp103 is up"
ip route add default table 103 dev ppp103
ip route add default table 203 dev ppp103
IPWAN=`ip addr show ppp103 |grep inet |cut -d " " -f 6`
ip rule del prio 203
ip rule add from $IPWAN lookup 203 prio 203
elif $status = 7 then
#line 123
ppp101=`/sbin/ifconfig -a | grep "ppp101"`
# echo "ppp101 is up"
ip route add default table 101 dev ppp101
ip route add default table 201 dev ppp101
IPWAN=`ip addr show ppp101 |grep inet |cut -d " " -f 6`
ip rule del prio 201
ip rule add from $IPWAN lookup 201 prio 201
ppp102=`/sbin/ifconfig -a | grep "ppp102"`
# echo "ppp102 is up"
ip route add default table 102 dev ppp102
ip route add default table 202 dev ppp102
IPWAN=`ip addr show ppp102 |grep inet |cut -d " " -f 6`
ip rule del prio 202
ip rule add from $IPWAN lookup 202 prio 202
ppp103=`/sbin/ifconfig -a | grep "ppp103"`
# echo "ppp103 is up"
ip route add default table 103 dev ppp103
ip route add default table 203 dev ppp103
IPWAN=`ip addr show ppp103 |grep inet |cut -d " " -f 6`
ip rule del prio 203
ip rule add from $IPWAN lookup 203 prio 203
elif $status = 8 then
#use line 4
ppp104=`/sbin/ifconfig -a | grep "ppp104"`
# echo "ppp104 is up"
ip route add default table 104 dev ppp104
ip route add default table 204 dev ppp104
IPWAN=`ip addr show ppp104 |grep inet |cut -d " " -f 6`
ip rule del prio 204
ip rule add from $IPWAN lookup 204 prio 204
elif $status = 9 then
#use line 1 and 4
ppp101=`/sbin/ifconfig -a | grep "ppp101"`
# echo "ppp101 is up"
ip route add default table 101 dev ppp101
ip route add default table 201 dev ppp101
IPWAN=`ip addr show ppp101 |grep inet |cut -d " " -f 6`
ip rule del prio 201
ip rule add from $IPWAN lookup 201 prio 201
ppp104=`/sbin/ifconfig -a | grep "ppp104"`
# echo "ppp104 is up"
ip route add default table 104 dev ppp104
ip route add default table 204 dev ppp104
IPWAN=`ip addr show ppp104 |grep inet |cut -d " " -f 6`
ip rule del prio 204
ip rule add from $IPWAN lookup 204 prio 204
elif $status = 10 then
#use line 24
ppp102=`/sbin/ifconfig -a | grep "ppp102"`
# echo "ppp102 is up"
ip route add default table 102 dev ppp102
ip route add default table 202 dev ppp102
IPWAN=`ip addr show ppp102 |grep inet |cut -d " " -f 6`
ip rule del prio 202
ip rule add from $IPWAN lookup 202 prio 202
ppp104=`/sbin/ifconfig -a | grep "ppp104"`
# echo "ppp104 is up"
ip route add default table 104 dev ppp104
ip route add default table 204 dev ppp104
IPWAN=`ip addr show ppp104 |grep inet |cut -d " " -f 6`
ip rule del prio 204
ip rule add from $IPWAN lookup 204 prio 204
elif $status = 11 then
#line 124
ppp101=`/sbin/ifconfig -a | grep "ppp101"`
# echo "ppp101 is up"
ip route add default table 101 dev ppp101
ip route add default table 201 dev ppp101
IPWAN=`ip addr show ppp101 |grep inet |cut -d " " -f 6`
ip rule del prio 201
ip rule add from $IPWAN lookup 201 prio 201
ppp102=`/sbin/ifconfig -a | grep "ppp102"`
# echo "ppp102 is up"
ip route add default table 102 dev ppp102
ip route add default table 202 dev ppp102
IPWAN=`ip addr show ppp102 |grep inet |cut -d " " -f 6`
ip rule del prio 202
ip rule add from $IPWAN lookup 202 prio 202
ppp104=`/sbin/ifconfig -a | grep "ppp104"`
# echo "ppp104 is up"
ip route add default table 104 dev ppp104
ip route add default table 204 dev ppp104
IPWAN=`ip addr show ppp104 |grep inet |cut -d " " -f 6`
ip rule del prio 204
ip rule add from $IPWAN lookup 204 prio 204
elif $status = 12 then
#use line 3 and 4
ppp103=`/sbin/ifconfig -a | grep "ppp103"`
# echo "ppp103 is up"
ip route add default table 103 dev ppp103
ip route add default table 203 dev ppp103
IPWAN=`ip addr show ppp103 |grep inet |cut -d " " -f 6`
ip rule del prio 203
ip rule add from $IPWAN lookup 203 prio 203
ppp104=`/sbin/ifconfig -a | grep "ppp104"`
# echo "ppp104 is up"
ip route add default table 104 dev ppp104
ip route add default table 204 dev ppp104
IPWAN=`ip addr show ppp104 |grep inet |cut -d " " -f 6`
ip rule del prio 204
ip rule add from $IPWAN lookup 204 prio 204
elif $status = 13 then
#line 134
ppp101=`/sbin/ifconfig -a | grep "ppp101"`
# echo "ppp101 is up"
ip route add default table 101 dev ppp101
ip route add default table 201 dev ppp101
IPWAN=`ip addr show ppp101 |grep inet |cut -d " " -f 6`
ip rule del prio 201
ip rule add from $IPWAN lookup 201 prio 201
ppp103=`/sbin/ifconfig -a | grep "ppp103"`
# echo "ppp103 is up"
ip route add default table 103 dev ppp103
ip route add default table 203 dev ppp103
IPWAN=`ip addr show ppp103 |grep inet |cut -d " " -f 6`
ip rule del prio 203
ip rule add from $IPWAN lookup 203 prio 203
ppp104=`/sbin/ifconfig -a | grep "ppp104"`
# echo "ppp104 is up"
ip route add default table 104 dev ppp104
ip route add default table 204 dev ppp104
IPWAN=`ip addr show ppp104 |grep inet |cut -d " " -f 6`
ip rule del prio 204
ip rule add from $IPWAN lookup 204 prio 204
elif $status = 14 then
#line 234
ppp102=`/sbin/ifconfig -a | grep "ppp102"`
# echo "ppp102 is up"
ip route add default table 102 dev ppp102
ip route add default table 202 dev ppp102
IPWAN=`ip addr show ppp102 |grep inet |cut -d " " -f 6`
ip rule del prio 202
ip rule add from $IPWAN lookup 202 prio 202
ppp103=`/sbin/ifconfig -a | grep "ppp103"`
# echo "ppp103 is up"
ip route add default table 103 dev ppp103
ip route add default table 203 dev ppp103
IPWAN=`ip addr show ppp103 |grep inet |cut -d " " -f 6`
ip rule del prio 203
ip rule add from $IPWAN lookup 203 prio 203
ppp104=`/sbin/ifconfig -a | grep "ppp104"`
# echo "ppp104 is up"
ip route add default table 104 dev ppp104
ip route add default table 204 dev ppp104
IPWAN=`ip addr show ppp104 |grep inet |cut -d " " -f 6`
ip rule del prio 204
ip rule add from $IPWAN lookup 204 prio 204
elif $status = 15 then
#use all
ppp101=`/sbin/ifconfig -a | grep "ppp101"`
# echo "ppp101 is up"
ip route add default table 101 dev ppp101
ip route add default table 201 dev ppp101
IPWAN=`ip addr show ppp101 |grep inet |cut -d " " -f 6`
ip rule del prio 201
ip rule add from $IPWAN lookup 201 prio 201
ppp102=`/sbin/ifconfig -a | grep "ppp102"`
# echo "ppp102 is up"
ip route add default table 102 dev ppp102
ip route add default table 202 dev ppp102
IPWAN=`ip addr show ppp102 |grep inet |cut -d " " -f 6`
ip rule del prio 202
ip rule add from $IPWAN lookup 202 prio 202
ppp103=`/sbin/ifconfig -a | grep "ppp103"`
# echo "ppp103 is up"
ip route add default table 103 dev ppp103
ip route add default table 203 dev ppp103
IPWAN=`ip addr show ppp103 |grep inet |cut -d " " -f 6`
ip rule del prio 203
ip rule add from $IPWAN lookup 203 prio 203
ppp104=`/sbin/ifconfig -a | grep "ppp104"`
# echo "ppp104 is up"
ip route add default table 104 dev ppp104
ip route add default table 204 dev ppp104
IPWAN=`ip addr show ppp104 |grep inet |cut -d " " -f 6`
ip rule del prio 204
ip rule add from $IPWAN lookup 204 prio 204
fi
ip route flush cache
/etc/ppp/ip-up.d/0nat
fi
oldstatus=$status
sleep 5
done
#0000 0 none
#0001 1 line 1 only
#0010 2 line 2 only
#0011 3 line 1 and 2
#0100 4 line 3 only
#0101 5 line 1 and 3
#0110 6 line 2 and 3
#0111 7 line 1 2 and 3
#1000 8 line 4
#1001 9 line 1 and 4
#1010 10 line 2 and 4
#1011 11 line 1 2 and 4
#1100 12 line 3 and 4
#1101 13 line 1 3 and 4
#1110 14 line 2 3 and 4
#1111 15 all