Load Balancing Your Internet connection
This daemon is used to load balance the internet connections you have via your linux box.
More details will be added later on. For now please contact us at support@sbi-secureit.com for explanations and customization.
Daemon will be put in /etc/rc.d/init.d
#ls -l
-rwxr-xr-x 1 root root 941 Jan 24 2003 anacron
-rwxr-xr-x 1 root root 1458 Feb 25 2003 apmd
..............................................
-rwxr-xr-x 1 root root 2163 Feb 26 2003 kudzu
-rwxr-xr-x 1 root root 322 Oct 28 2006 lbwd <<<<<<<<<<
-rwxr-xr-x 1 root root 3940 Oct 30 2006 loadbalancingwatchdog <<<<<<<
-rwxr-xr-x 1 root root 5080 Jan 7 2003 netfs
-rwxr-xr-x 1 root root 6785 Oct 28 2006 network
content of lbwd is as follows
case "$1" in
start)
nohup /etc/init.d/loadbalancingwatchdog &
;;
stop)
echo stop
;;
status)
echo status
;;
restart|reload)
#cd $CWD
$0 stop
$0 start
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac
exit 0
content of /etc/init.d/loadbalancingwatchdog is as follows
#flushing policy
#iptables -F
#default policy drop
#iptables -t filter -P FORWARD DROP
#iptables -t filter -P INPUT DROP
#iptables -t filter -P OUTPUT DROP
# to hide nat internal network.
#iptables -t nat -I POSTROUTING -s 192.168.2.0/24 -j MASQUERADE
#to allow fw to speak to itself.
#iptables -A INPUT -i lo -j ACCEPT
#iptables -A OUTPUT -o lo -j ACCEPT
#to allow internal network to access the internet.
#iptables -A FORWARD -i eth0 -o eth1 -m state --state ESTABLISHED,RELATED -j ACCEPT
#iptables -A FORWARD -i eth1 -o eth0 -s 192.168.2.0/24 -j ACCEPT
#to allow internal network and wireless host to access ssh on the fw.
#iptables -I INPUT -s 192.168.2.0/24 -i eth1 -p tcp --dport 22 -j ACCEPT
#iptables -I INPUT -s 192.168.1.10 -i eth0 -p tcp --dport 22 -j ACCEPT
#iptables -I OUTPUT -d 192.168.2.0/24 -o eth1 -p tcp --sport 22 -m state --state ESTABLISHED,RELATED -j ACCEPT
#iptables -I OUTPUT -d 192.168.1.10 -o eth0 -p tcp --sport 22 -m state --state ESTABLISHED,RELATED -j ACCEPT
#to allow the firewall to ping routers and servers
#iptables -t filter -A OUTPUT -p icmp -j ACCEPT
#iptables -t filter -A INPUT -p icmp -m state --state ESTABLISHED,RELATED -j ACCEPT
#to allow traceroute
#iptables -t filter -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
#iptables -t filter -A OUTPUT -j ACCEPT
#saving policy
#service iptables save
echo 1 > /proc/sys/net/ipv4/ip_forward
ip route add default equalize nexthop via 192.168.1.11 dev eth0 nexthop via 192.168.1.1 dev eth0
#www.sbi-secuteit.com
route add -host 64.202.163.153 gw 192.168.1.1
#nol network
#dns1
route add -host 62.140.73.1 gw 192.168.1.1
#dns2
route add -host 62.140.73.2 gw 192.168.1.1
#dslam
route add -host 172.16.134.40 gw 192.168.1.1
#nol nasr city
route add -host 62.140.80.1 gw 192.168.1.1
#nol router
route add -host 217.54.142.137
#nol internal address 192.168.1.1
#tedata router
route add -host 163.121.138.2 gw 192.168.1.11
#tedata nasr city
route add -host 163.121.170.117 gw 192.168.1.11
#tedata internal ip 192.168.1.11
#ted dslam gatew 196.202.31.67
route add -host 196.202.31.67 gw 192.168.1.11
#ted dns 1
#ted dns 2
oldstat=both;
newstat=both;
while true
do
sleep 60;
n=`ping -c 1 62.140.80.1 | grep from | grep 64`;
t=`ping -c 1 163.121.170.117 | grep from | grep 64`;
echo `date` >> /var/log/lbwd.log;
echo nol is $n >> /var/log/lbwd.log ;
echo tedata is $t >> /var/log/lbwd.log ;
echo $n | awk '{ print $1 }' > nol-file ;
echo $t | awk '{ print $1 }' > ted-file ;
nol=`cat nol-file`;
ted=`cat ted-file`;
echo nol is $nol >> /var/log/lbwd.log;
echo ted is $ted >> /var/log/lbwd.log;
if [[ "$nol" == "64" ]]
then
if [[ "$ted" == "64" ]]
then
echo both are working equalize >> /var/log/lbwd.log;
newstat=both;
else
echo nol rules >> /var/log/lbwd.log ;
newstat=nol;
fi
else
if [[ "$ted" == "64" ]]
then
echo tedata rules >> /var/log/lbwd.log;
newstat=tedata;
else
echo bayzeen equalize >> /var/log/lbwd.log;
newstat=both;
fi
fi
echo new stat is === $newstat >> /var/log/lbwd.log
if [[ "$newstat" == "$oldstat" ]]
then
echo old is new i will do nothing >> /var/log/lbwd.log;
elif [[ "$newstat" == "both" ]]
then
echo old is nol or tedata, new is both i will delete default and add both >> /var/log/lbwd.log;
route del default;
ip route add default equalize nexthop via 192.168.1.11 dev eth0 nexthop via 192.168.1.1 dev eth0;
elif [[ "$newstat" == "nol" ]]
then
echo old is ted or both, new is nol >> /var/log/lbwd.log;
route del default;
route add default gw 192.168.1.1;
else
echo old is nol or both, new is ted >> /var/log/lbwd.log;
route del default;
route add default gw 192.168.1.11;
fi
oldstat=newstat
done
We know the script is not generic enough for out of the box use. Please contact support@sbi-secureit.com so we can help you customize it.