Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've been looking for some time now, how to achieve that, but I can't seem to find similar solutions or synthesize one from my knowledge.

Here are the details about my setup: I have one gateway/router that has the uplink to the internet. "Behind" that are several different servers. Some of those have a public IP, others don't. Either way, all the services I wanted to expose are exposed by either unblocking the respective port on the target IP or DNATing the port through to one of the machines with no public IP. That whole setup works nicely (for the bigger part it's a netfilter-based ruleset in combination with a few routing table entries).

Now the problem: sometimes machines behind the router can be down (I can't afford extra redundancy at the moment). If that happens, I would like the user of a service - in particular HTTP - to have a "better" user experience than a network timeout and offer a "backup" server that would only display a short notice about the fact that the service behind the router is down at the moment. So if the router can't reach the service, it should re-route the traffic dynamically to the "backup".

Does anyone know of a solution to this problem or can suggest a way how to approach it? Suggestions for search terms are also welcome ...

share|improve this question
up vote 3 down vote accepted

One solution would be to use a loadbalancer like HAProxy. It supports the concept of a backup server, so you can route your traffic to your normal server as long as it answers to the regular checks the loadbalancer does. If it doesn't answer anymore, traffic can get routed to backup servers which in your case could simply display a "sorry" note.

The downside of this approach is of course that you have to maintain the loadbalancer, which might be another single point of failure. If your gateway/router is an actual linux system (as opposed to some plastic box), this is probably not an issue, as it already is a single point of failure and can probably also run the loadbalancer :)

More general, the problem to solve is not to redirect the traffic (there are many solutions for that) but to actually detect that a host is down and then to change the routing/redirection accordingly. The same is needed when the server goes up again, so that traffic is routed to the actual server agin.

share|improve this answer
thanks. Actually the detection in this particular case is no problem at all, so we can skip those considerations. Thanks for the pointer to HAProxy. +1 for now, I'm still reading through it. – 0xC0000022L Mar 9 '11 at 21:11
do you know any alternatives, or is HAProxy the only one? Also, is "loadbalancer" really the (search) term I'm looking for, or do you have other suggestions as well? – 0xC0000022L Mar 10 '11 at 21:15
Loadbalancers often have both of the required features to detect failed servers and to re-route traffic accordingly. You can also try nginx, Apache, or even LVS. There are many variants which do one of these well, but not the other. Loadbalancers do both well, as they are built exactly for this purpose (additionally to,. well balance load) – Holger Just Mar 10 '11 at 23:58
thanks for your help and the further pointers. Your help is much appreciated. – 0xC0000022L Mar 11 '11 at 1:53

The cheapest solution, you'd have to write a script which polls the backend server and updates your port forwarding when it goes down. You'd forward the traffic to a different server which contains your error message.

The details of the script depend completely on the specific details of your systems. Some very rough pseudo bash code:

wget backendserver > /dev/null
if failed; then
  iptables -D <port forward rule>
  iptables -A <new forward rule>
  verify iptables is sending to the backend

In our environment, all traffic is forwarded to one server, which then proxies to the backends. Its setup to display proper messages during outages. However it can still fail causing timeouts. Its dedicated to its task though, making outages rare. The next step would be to make it part of a cluster, to increase uptime; for us the cost/benefit isn't there.

share|improve this answer
thanks. How do you run this then? Has to be a pretty tight loop, does it not? – 0xC0000022L Mar 9 '11 at 21:10

Your Answer


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.