linux-admin.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Gateway Switch script
@ 2003-08-28 10:24 Murali Potla
  2003-08-28 12:36 ` Jeff Largent
  2003-08-28 12:49 ` Vitalie Cherpec
  0 siblings, 2 replies; 3+ messages in thread
From: Murali Potla @ 2003-08-28 10:24 UTC (permalink / raw)
  To: Murali Potla, linux-admin

Hi,

Does any body has a script to automatically switch the default gateway
between two IPs. ?

I have two ISP connections. I want to switch between them when one is
down 


Regards
Murali
 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Gateway Switch script
  2003-08-28 10:24 Gateway Switch script Murali Potla
@ 2003-08-28 12:36 ` Jeff Largent
  2003-08-28 12:49 ` Vitalie Cherpec
  1 sibling, 0 replies; 3+ messages in thread
From: Jeff Largent @ 2003-08-28 12:36 UTC (permalink / raw)
  To: Murali Potla; +Cc: linux-admin

You could use something like this, run out of cron.

#!/bin/bash

$DEF='192.168.1.1'
$BACK='192.168.2.1'
$CURRENT=`netstat -rn | grep "^0.0.0.0" | awk '{print $2}'`

# if $DEF is current check and switch to backup if down
if [ $CURRENT = $DEF ]; then
   ping -c1 -w5 $DEF

   if [ $? > 0 ]; then
     route del default gw $DEF
     route add default gw $BACK
   fi
# else check the backup and switch to def if down
else
   ping -c1 -w $BACK

   if [ $? > 0 ]; then
     route del default gw $BACK
     route add default gw $DEF
   fi
fi

This is totally untested so you milage may vary.





Murali Potla wrote:
> Hi,
> 
> Does any body has a script to automatically switch the default gateway
> between two IPs. ?
> 
> I have two ISP connections. I want to switch between them when one is
> down 
> 
> 
> Regards
> Murali
>  
> 
> -
> To unsubscribe from this list: send the line "unsubscribe linux-admin" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
> 

-- 
Jeff Largent                   ImageLinks, Inc.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Gateway Switch script
  2003-08-28 10:24 Gateway Switch script Murali Potla
  2003-08-28 12:36 ` Jeff Largent
@ 2003-08-28 12:49 ` Vitalie Cherpec
  1 sibling, 0 replies; 3+ messages in thread
From: Vitalie Cherpec @ 2003-08-28 12:49 UTC (permalink / raw)
  To: Murali Potla; +Cc: linux-admin

>
>
>Does any body has a script to automatically switch the default gateway
>between two IPs. ?
>I have two ISP connections. I want to switch between them when one is
>down 
>  
>

You can set up your default route to be a multipath route. Then you
could use both connections simultaneously and continue to use the
other one if one is down. There is no need to switch default gateway
with a script. Your kernel will figure out when to stop using the dead
route and how to do NAT.

Check these urls:

    http://lartc.org/howto/lartc.rpdb.multiple-links.html
    http://www.ssi.bg/~ja/#routes
    http://www.ssi.bg/~ja/nano.txt

                    Vitalie


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-08-28 12:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-08-28 10:24 Gateway Switch script Murali Potla
2003-08-28 12:36 ` Jeff Largent
2003-08-28 12:49 ` Vitalie Cherpec

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).