Hi Jay,
I read your mail regarding "How to switch between two internet connections" yesterday only. I had a faint idea on how to do it, but since I was surfing from a windows system I was unable to clarify some of my doubts. But now since I have tried it on my linux system I am sure it will work on your system too.
Make a script by the name eg. gwchk.sh in /root with the following content,
-----------------------------------------------------------------------------------------------------------------------------
while
true <-------- Outermost loop
do
while ping -c 1 192.168.0.1 > /dev/null <-------- Inner loop 1
do
sleep 1
done
route del default
route add default gw 192.168.0.50
while ping -c 1 192.168.0.50 > /dev/null <-------- Inner loop 2
do
ping -c 1 192.168.0.1 > /dev/null
[ $? -eq 0 ] && break
done
route del default
route add default gw 192.168.0.1
done
---------------------------------------------------------------------------------------------------------------------------
# nohup /root/gwchk.sh &
You can run the script as root by the above command, since it will put the script running in the background and also allow you to logout from the root's terminal. (Since leaving a root terminal unattended is insecure).
The outermost loop of the script is a neverending one. Once the control enters the inner loop 1 it will start pinging your default gateway (192.168.0.1) within an interval of 1 second to check if the gateway is up. The moment the gateway stops replying the loop breaks
and the default gateway is deleted and new gateway (192.168.0.50) added.
Then it enters the inner loop 2 where it pings your new gateway (192.168.0.50) to check if it is up and inside the loop it pings the old gateway (192.168.0.1) to check if it has come up or not. Once the old gateway comes up, the loop breaks and the default gateway is deleted and new gateway (192.168.0.1), i.e. the old one added.
With this change the outer most loop ends and again goes into Inner loop 1 to ping the gateway (192.168.0.1) till it is down and then...
Regards,
jay shi <[EMAIL PROTECTED]> wrote:
Hi friends,
i need a help from u all,I have two internet
connetion to my linux server. I want to implement it
as follows,
when first internet connetion get down ,then my
second net connetion should come up immediatly and
similarly when my first internet connetion is come up
again then my gateway should switch to first gatway.
here i want to use user my first internet
connetion ( gateway 192.168.0.1) as a primary net .
The simple script for this which i written is as
follows
wget -t 1 --timeout=4 --bind-address 192.168.0.80
http://< some ip >
if
[ -s /root/index.html ]
then
echo " Net is working"
route del default
route add default gw 192.168.0.1
else
echo " Net is down but it is up with anothe gw "
route del default
route add default gw 192.168.0.50
fi
rm -f /root/index.html
here 192.168.0.80 is my server ip.My problem is
by this script, when net started through primary
gatway then i am not able to switch to my primary
gateway ( 192.168.0.1).
hwo to do this, any suggession,tips for this ?
Thanks in advance
thanks & regards
jayesh :-)
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Love cheap thrills? Enjoy PC-to-Phone calls to 30+ countries for just 2ยข/min with Yahoo! Messenger with Voice.
***Archives:
http://groups.yahoo.com/group/linuxvadapav/messages
***Group Usage Guidelines (Please Read):
http://groups.yahoo.com/group/linuxvadapav/files/mailing_rules
YAHOO! GROUPS LINKS
- Visit your group "linuxvadapav" on the web.
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
