Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want to set up an Ubuntu router with automatic fail-over to a 3G link. I can probably set up routing and link aggregation, but I don't know how to monitor link status and dial the 3G link in case it is down. Pointers to helpful resources greatly appreciated.

share|improve this question
2  
(Congratulations, I believe you have asked question #1000 on the site!) –  8128 Sep 8 '10 at 16:22
    
Congrats go to stackexchange -- i rolled back the edit because i am specifically looking on a script that will dial the 3g link; i can grep ping's stdout pretty well. –  user2132 Sep 8 '10 at 17:19
    
Welcome to SE. Please be more specific in the question body, not the title. Also tags in titles are strongly discouraged unless they can be made part of the title text. Otherwise, try and avoid rolling back moderator edits. Try and use tags to target the type of answers you expect –  Diago Sep 8 '10 at 17:36

1 Answer 1

I'm not sure there's anything out there that could do this for you... However, you could, with a bit of scripting, a bit of Googling, cobble together a script that:

  • Every 10 minutes, pings google with a timeout of 2 seconds and only from your "fixed" connection (not the 3G one) (use the -I flag).
  • If the ping succeeds, and you're on the fixed connection, do nothing.
  • If you're on 3G and the ping over the fixed connection works, take the 3G adapter down.
  • If it fails, bring up the 3G adaptor.

Here's my quick attempt:

#! /bin/bash

CONNECTION=1

main()
{
    if ping -q -c 1 -w 1 -I eth0 google.com > /dev/null ; then
        echo "Connection is ok!"

        if [ $CONNECTION -eq 0 ] ; then
            # take the 3g connection down
            ifconfig 3GADAPTERNAME down
            CONNECTION=1
        fi
    else
        echo "Connection is dead! Long live the connection!"

        if [ $CONNECTION -eq 1 ] ; then
            # turn the 3g connection on
            ifconfig 3GADAPTERNAME up
            CONNECTION=0
        fi
    fi

    sleep 5
    main
}

main

Obviously replace 3GADAPTERNAME with your adapter's name. switch out eth0 if your main connection is different. Make sure it is set to automatically connect (so when it's allowed to, it does). The script will need to run as root.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.