Announcement

Collapse
No announcement yet.

failover script for possible ISP downtime

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • failover script for possible ISP downtime

    hi all,
    i'm wondering if anyone can guide me to a batch script or a vps or shell (could run it on cygwin) that could help me do failover solution for possible ISP downtime (i have a windows server with two NICs) with two ISP's one of them is backup. the thing is, i'm looking for a way when a ping times out on one interface, the script immediately switches the default route to the other interface..

    i'm a bit green with the whole batch/shell scripting techniques.
    i've tried my luck using a shell script on cygwin but that resulted in a failure..
    so any advice would be appreciated
    thanks,
    Roland

  • #2
    Re: failover script for possible ISP downtime

    Originally posted by silent View Post
    failover solution for possible ISP downtime (i have a windows server with two NICs) with two ISP's one of them is backup.
    How business critical system you are aiming at? If you need serious reliability, consider getting a router based high availability solution from your ISP.

    Would you like to fall back to the primary connection when it is online again, or can you stick routing through then the fail-over connection?

    Here is a quick draft on Powershell, as I've recently wrote lots of Powershell scripts. The idea remains, even if you would like to convert it into batch, VBS or Bash shell script. If you have troubles converting the script, just ask for help.

    Code:
    new-variable -Option Constant -name primaryISP -value "192.168.10.1"
    new-variable -Option Constant -name secondaryISP -value "192.168.1.1"
    
    function changeRoute($activeISP)
    {
        $gw = 0
        switch($activeISP)
        {
            0{$gw = $primaryISP}
            1{$gw = $secondaryISP}
        }
        $cmd = "route change 0.0.0.0 mask 0.0.0.0 $gw"
        invoke-expression $cmd
    }
    
    function pingISP($ispDefGW)
    {
        $alive = $false
        
        $pingCommand = "ping -n 1 $ispDefGW"
        $res = invoke-expression $pingCommand
        
        if($res -match("reply from"))
        {
            $alive = $true
        }
        
        return $alive
    }
    
    function main()
    {
        $activeISP = 0
        
        while($true)
        {
            $primary = pingIsp($primaryISP)
            $secondary = pingIsp($secondaryISP)
            
            # Primary link has fallen
            if(!$primary)
            {
                if($secondary)
                {
                    $activeISP = 1
                    changeRoute($activeISP)
                }
                else
                {
                    # Oh noes! both are down!
                }
            }
            # Primary link is alive
            else
            {
                #Fall back to primary if using secondary
                if($activeISP -ne 0)
                {
                    $activeISP = 0
                    changeRoute($activeISP)
                }
            }
            
            start-sleep -s 5
        }
    }
    
    main
    -vP

    Comment


    • #3
      Re: failover script for possible ISP downtime

      Code:
      # Oh noes! both are down!
      I lol'd.
      Wesley David
      LinkedIn | Careers 2.0
      -------------------------------
      Microsoft Certifications: MCSE 2003 | MCSA:Messaging 2003 | MCITP:EA, SA, EST | MCTS: a'plenty | MCDST
      Vendor Neutral Certifications: CWNA
      Blog: www.TheNubbyAdmin.com || Twitter: @Nonapeptide || GTalk, Reader and Google+: [email protected] || Skype: Wesley.Nonapeptide
      Goofy kitten avatar photo from Troy Snow: flickr.com/photos/troysnow/

      Comment


      • #4
        Re: failover script for possible ISP downtime

        Or wait for TMG
        Marcel
        Technical Consultant
        Netherlands
        http://www.phetios.com
        http://blog.nessus.nl

        MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
        "No matter how secure, there is always the human factor."

        "Enjoy life today, tomorrow may never come."
        "If you're going through hell, keep going. ~Winston Churchill"

        Comment

        Working...
        X