Failover routing with OpenBSD and ifstated

Can of worms

  • Homepage

Feb 14: Failover routing with OpenBSD and ifstated

The past few months I've been suffering from an unreliable adsl line, with some prolonged outages. I've got a 3g stick to fall back onto, but that needed to be enabled manually, so I decided to automate the process (hopefully I'll also remember to top-up the 3g stick!) using ifstated. It turned out to be really simple, but there's a lack of simple examples, so I thought it might be worth publishing.

The config is such that ifstated pings my router address every 10 seconds to make sure it's alive. When ADSL is live this is just a single hop to the router. Should it not get an answer in 5 seconds it will fail over to the 3g connection, if it starts getting an answer form the router (this time over the internet) it will fail back to adsl.

Replace 127.0.0.1 with your adsl ip address and tweak the timings as you see fit.

  1.  
  2. ping = '( "ping -w 5 -q -c 1 127.0.0.1 > /dev/null" every 10 ) '
  3.  
  4. state one {
  5.        init {
  6.                 run "logger -p daemon.notice -t ifstated 'Switching to adsl!'"
  7.                 run "kill `cat /var/run/ppp0.pid`"
  8.        }
  9.        if ! ( $ping ) {
  10.                set-state two
  11.        }
  12. }
  13.  
  14. state two {
  15.  
  16.        init {
  17.                 run "logger -p daemon.notice -t ifstated 'Switching to threeg!'"
  18.                 run "pppd call threeg"
  19.        }
  20.  
  21.        if ( $ping  ) {
  22.                set-state one
  23.        }
  24. }
  25.  
Posted by dom in tech Comments: (0) Trackbacks: (0)

Trackbacks
Trackback specific URI for this entry

No Trackbacks

Comments
Display comments as (Linear | Threaded)

No comments


Add Comment

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.
You can use [geshi lang=lang_name [,ln={y|n}]][/geshi] tags to embed source code snippets.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

BBCode format allowed
 
 

Archives

  • May 2013
  • April 2013
  • March 2013
  • Recent...
  • Older...

Categories

  • XML garden
  • XML life
  • XML tech
  • XML tooting


All categories

Links

  • NerdyToad
  • Leggetter
  • Bifferboard
  • Reel SVN log

Syndicate This Blog

  • XML RSS 0.91 feed
  • XML RSS 1.0 feed
  • XML RSS 2.0 feed
  • ATOM/XML ATOM 0.3 feed
  • ATOM/XML ATOM 1.0 feed
  • XML RSS 2.0 Comments

Blog Administration

Open login screen
 

Layout by Andreas Viklund | Serendipity template by Carl