Linux Scripting

Taking care of your Linux box.

Linux Scripting

Postby mejam » Tue Oct 28, 2008 6:46 pm

Hy all...I am new to scripting...i need a linux script that will do both Load Balancing and Fail over for my network....I am running CentOS on my server and i have two DSL modems....Please help...!!


Regards

Abdulrehman
Regards
Abdulrehman
mejam
Havaldaar
 
Posts: 127
Joined: Sat Oct 18, 2008 12:30 pm
WLM: bmw1000cc@hotmail.com
Yahoo Messenger: vagabond_aw@yahoo.com
Location: Lahore

Re: Linux Scripting

Postby LinuxFreaK » Wed Oct 29, 2008 2:53 am

Dear mejam,
Salam,

mejam wrote:Hy all...I am new to scripting...i need a linux script that will do both Load Balancing and Fail over for my network....I am running CentOS on my server and i have two DSL modems....Please help...!!


FYI, http://lnlb.sourceforge.net and http://blog.taragana.com/index.php/arch ... -on-linux/

Best Regards.
Farrukh Ahmed
LinuxFreaK
Site Admin
 
Posts: 5132
Joined: Fri May 02, 2003 10:24 am
ICQ: 82075802
Website: http://www.linuxpakistan.net/wiki/index.php?pagename=LinuxFreak
WLM: f4fahmed@hotmail.com
Yahoo Messenger: f4fahmed@yahoo.com
AOL: linuxpakistan@aol.com
Location: Karachi

Postby mejam » Wed Oct 29, 2008 3:18 am

Dear Farrukh bhai,
Thanks for ur help but i have already gone through these links...nothing good working for me...that why i asked for a complete script.. :cry:
Regards

Abdulrehman
mejam
Havaldaar
 
Posts: 127
Joined: Sat Oct 18, 2008 12:30 pm
WLM: bmw1000cc@hotmail.com
Yahoo Messenger: vagabond_aw@yahoo.com
Location: Lahore

Postby x2oxen » Thu Oct 30, 2008 9:10 am

Well that thing worked for me why its not working for you? You missing anything?
Muhammad Usman
+92-321-6640501
Chemonics International
http://usmanpk.com
x2oxen
Major General
 
Posts: 1114
Joined: Wed Aug 22, 2007 3:17 pm
Website: http://usmanpk.com
WLM: x2oxen@hotmail.com
Yahoo Messenger: x2oxen
Location: Faisalabad

Postby mejam » Thu Oct 30, 2008 7:34 pm

aaah...figured it out....thanks for help..
Regards

Abdulrehman
mejam
Havaldaar
 
Posts: 127
Joined: Sat Oct 18, 2008 12:30 pm
WLM: bmw1000cc@hotmail.com
Yahoo Messenger: vagabond_aw@yahoo.com
Location: Lahore

Postby lambda » Thu Oct 30, 2008 8:07 pm

please share your script so that others can use it.
Watch out for the Manners Taliban!
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?
lambda
Major General
 
Posts: 3452
Joined: Tue May 27, 2003 7:04 pm
Website: http://www.hungry.com/~fn/
Location: Lahore

Postby mejam » Thu Oct 30, 2008 8:27 pm

This scrip it for load balancing only.....mentioned link will guide about fail over
http://blog.taragana.com/index.php/arch ... -on-linux/
======================================================================
#!/bin/bash
#
# bal_local Load-balance internet connection over two local links
#
# Author: Abdulrehman <arvagabond5@gmail.com>
#

# Set devices:
DEV1=${1-eth0} # default eth0
DEV2=${2-eth1} # default eth1

# Get IP addresses of our devices:
ip1=`ifconfig $DEV1 | grep inet | awk '{ print $2 }' | awk -F: '{ print $2 }'`
ip2=`ifconfig $DEV2 | grep inet | awk '{ print $2 }' | awk -F: '{ print $2 }'`

# Get default gateway for our devices:
gw1=`route -n | grep $DEV1 | grep '^0.0.0.0' | awk '{ print $2 }'`
gw2=`route -n | grep $DEV2 | grep '^0.0.0.0' | awk '{ print $2 }'`

echo "$DEV1: IP=$ip1 GW=$gw1"
echo "$DEV2: IP=$ip2 GW=$gw2"

### Definition of routes ###

# Check if tables exists, if not -> create them:
if [ -z "`cat /etc/iproute2/rt_tables | grep '^251'`" ] ; then
echo "251 rt_dev1" >> /etc/iproute2/rt_tables
fi
if [ -z "`cat /etc/iproute2/rt_tables | grep '^252'`" ] ; then
echo "252 rt_dev2" >> /etc/iproute2/rt_tables
fi

# Define routing tables:
ip route add default via $gw1 table rt_dev1
ip route add default via $gw2 table rt_dev2

# Create rules:
ip rule add from $ip1 table rt_dev1
ip rule add from $ip2 table rt_dev2

# If we already have a 'nexthop' route, delete it:
if [ ! -z "`ip route show table main | grep 'nexthop'`" ] ; then
ip route del default scope global
fi

# Balance links based on routes:
ip route add default scope global nexthop via $gw1 dev $DEV1 weight 1 nexthop via $gw2 dev $DEV2 weight 1

# Flush cache table:
ip route flush cache

# All done...
=======================================================================
Regards

Abdulrehman
mejam
Havaldaar
 
Posts: 127
Joined: Sat Oct 18, 2008 12:30 pm
WLM: bmw1000cc@hotmail.com
Yahoo Messenger: vagabond_aw@yahoo.com
Location: Lahore

Postby nomankhn » Fri Oct 31, 2008 6:11 am

mejam wrote:This scrip it for load balancing only.....mentioned link will guide about fail over
http://blog.taragana.com/index.php/arch ... -on-linux/
======================================================================
#!/bin/bash
#
# bal_local Load-balance internet connection over two local links
#
# Author: Abdulrehman <arvagabond5@gmail.com>
#

=======================================================================


Are u the author of this script? its great, tell us what problem come so u not able to use initially and how u resolve that.

Thanks,
Noman Liaquat
nomankhn
Colonel
 
Posts: 714
Joined: Wed Aug 07, 2002 8:00 pm

Postby x2oxen » Fri Oct 31, 2008 9:43 am

According to your this script i think that gwping script also needed to be modified. But this above script looks like a great piece of work. Who wrote that?
Muhammad Usman

+92-321-6640501

Chemonics International

http://usmanpk.com
x2oxen
Major General
 
Posts: 1114
Joined: Wed Aug 22, 2007 3:17 pm
Website: http://usmanpk.com
WLM: x2oxen@hotmail.com
Yahoo Messenger: x2oxen
Location: Faisalabad

Postby mejam » Fri Oct 31, 2008 10:10 pm

i wrote it with the help of a scripting professional....i have his CBTs of scripting...i could not have done this on my own....
Regards

Abdulrehman
mejam
Havaldaar
 
Posts: 127
Joined: Sat Oct 18, 2008 12:30 pm
WLM: bmw1000cc@hotmail.com
Yahoo Messenger: vagabond_aw@yahoo.com
Location: Lahore

Postby mejam » Fri Oct 31, 2008 10:13 pm

my machine was having a troubble...when it gets rebooted it shifted the LAN interfaces...eth0 became eth1 and eth1 turns to eth0....i just figured it out and fixed it....there was nothing wrong with the script at that time even
Regards

Abdulrehman
mejam
Havaldaar
 
Posts: 127
Joined: Sat Oct 18, 2008 12:30 pm
WLM: bmw1000cc@hotmail.com
Yahoo Messenger: vagabond_aw@yahoo.com
Location: Lahore

Postby mejam » Fri Oct 31, 2008 10:14 pm

and thats strange that i did not get any comments from farrukh bhai......? :D
Regards

Abdulrehman
mejam
Havaldaar
 
Posts: 127
Joined: Sat Oct 18, 2008 12:30 pm
WLM: bmw1000cc@hotmail.com
Yahoo Messenger: vagabond_aw@yahoo.com
Location: Lahore

Postby lambda » Fri Oct 31, 2008 11:12 pm

why is it strange?
Watch out for the Manners Taliban!
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?
lambda
Major General
 
Posts: 3452
Joined: Tue May 27, 2003 7:04 pm
Website: http://www.hungry.com/~fn/
Location: Lahore

Postby shakirz1 » Sat Nov 01, 2008 10:07 am

to stop lan card shifting put mac addresses of lan card in /etc/sysconfig/network-scripts/ifcfg-ethx.
shakirz1
Battalion Quarter Master Havaldaar
 
Posts: 207
Joined: Sat Aug 09, 2003 5:00 pm
Website: http://www.fattanis.cjb.net
WLM: shakirz1@hotmail.com
Yahoo Messenger: shakirz1@yahoo.com
Location: Karachi

Postby mejam » Sun Nov 02, 2008 1:16 am

Thanks for help buddy but i already have figured it out...things are just running fine... :)
Regards

Abdulrehman
mejam
Havaldaar
 
Posts: 127
Joined: Sat Oct 18, 2008 12:30 pm
WLM: bmw1000cc@hotmail.com
Yahoo Messenger: vagabond_aw@yahoo.com
Location: Lahore


Return to “%s” Administration

Who is online

Users browsing this forum: No registered users and 1 guest

cron