Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

OK, I have linux box with one cable WAN and GPRS modem (or lets say another WAN connection that is normally down). Is there any option to make this second link (GMPR/Ethernet/other) as backup connection that is used ONLY when the main link is not working properly?

I can detect the state of primary link simply by pinging specified server in internet (it is important that it cannot be the gateway, because sometimes the gateway is reachable, but rest of the internet is not...).

further - I can write this test in some bash script to periodically test connection and switch to backup link when the primary connection is broken. But when changing - the default route changes to the second connection and I'm not able to check in background if the primary link is still down...

So - is there any solution to set default route for all applications to backup link and still be able to route pings through primary link? What makes it more complicated I cannot put static route to test server always through primary link, as those "applications" that run on server also try to connect to this server and I want them to use backup link when primary is down...

Something similar I saw on linksys RV042 dual WAN router. It can monitor primary connection (while secondary is down), and when primary goes down - it uses secondary link, but when primary is up again - the secondary is disabled and all trafic is redirected throug primary link again.

share|improve this question

migrated from stackoverflow.com Sep 30 '09 at 13:53

This question came from our site for professional and enthusiast programmers.

5 Answers 5

I have a similar problem with our cable provider - the gateway may be reachable but the rest of the internet is not. I used traceroute to find a pingable host on the edge of the providers network as a test host for pings. You do do the same to find a host as a ping test destination / static route candidate.

share|improve this answer

with policy-routing you can use different routing tables depending on mark [ fwmark ] set in iptables. you can set different mark for the same host but different port numbers [ maybe you can run couple of test-services on your destination server on different ports ]...

or maybe you can set static route to few neighbour ip address of your destination server?

look at lartc for more info.

share|improve this answer

Choose some server that you never need to access over your backup link. It may be a next hop in traceroute after the gateway (you don't ever talk to that router anyway). Or just a service you'd never use over GPRS (e.g. streaming video). Create a static route to that server through the first link.

share|improve this answer

If you are flexible about what software you use for your firewall/routing, you could try a Shorewall setup like this: http://www.shorewall.net/MultiISP.html

I give this as an example because it is what I am using personally, so check to see if your preferred netfilter config tool, or other firewall/routing application, supports MultiISP functionality.

Using the listed LSM package, you are able to define actions that are taken on link up/down events. So when your primary link goes down you could execute the series of commands required to bring your secondary link up before traffic will be routed to it.

As for proper routing of ping packets to your test server in the above setup, see the section about applications at the #Applications anchor. (I'd post a direct link, but I"m restricted to only one URL)

Since Shorewall is a frontend to the lower level tools, you should be able to achieve whatever it is doing directly if that's more what you're looking for. You are able to route based on subtables in addition to the default routing table, and you can use fwmarks to direct packets to those subtables.

For example, in my 'ip route ls' I have:

10000:  from all fwmark 0x100 lookup DSL
10001:  from all fwmark 0x200 lookup WifiNet
share|improve this answer

It actually is easy.

Let's suppose ISP1 is the primary and ISP2 is the backup.

1.1.1.1 is the IP address of the ISP1's gateway.

2.2.2.2 is the IP addrss of the ISP2's gateway.

9.9.9.9 is the IP address reachable on ISP1 that you will use to detect if ISP1 is down or not.

First you need another routing table besides main table. Let's use table 10.

Add a default gateway to ISP1's gateway's IP address into table 10 like this:

# ip route add default via 1.1.1.1 table 10

And add a rule into Routing Policy DataBase (RPDB):

# ip rule add to 9.9.9.9 table 10

You can verify with:

# ip route list table 10
# ip rule list

Now it's up to you to write a script that detect if ping to 9.9.9.9 failed and change the default gateway accordingly. When ping to 9.9.9.9 failed, your script should change the default gateway so that traffic will get routed to the backup link. However, because of the rule and table we just added, ping (or any traffic) to 9.9.9.9 will still be routed thru the primary link.

You can test by changing the default gateway (by using route del default && route add default gw 2.2.2.2 ) and tracroute to 9.9.9.9

share|improve this answer

Your Answer

 
discard

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