Redirect IP to another if not available

I would consider a load balancer for this use case.

A load balancer will distribute connections across all of the backend servers you configure.

If one of your backend servers goes down, the load balancer will see that and not direct traffic to it anymore until it comes back up.

You can change how connections are distributed in various ways depending on the load balancer.

Here is some great documentation on using NGINX as a load balancer (there are many others):

http://nginx.org/en/docs/http/load_balancing.html


your client/application must handle the logic to retry the different servers/IPs.

if it can't, you can put a loadbalancer between the app and the servers to take care of that behavior.

out of the box, iptables can't do that.