I have a network like this: A is connected to a router(R) which is connected to a server(S)through 2 interfaces: eth0 and eth1. One of them is for backup. Consider that the server has IP SIP0 on eth0 and IP SIP1 on eth1, and the router has RIP on the interface connected to A.
How do I configure iptables so that all the requests made on port x on router R are redirected to the server S port y, even if only one of the interfaces ( eth0 or eth1 ) is down?
Consider that all the routes are working, and eth0 has a metric 1 route, and eth1 metric 2. I have thought to add 2 rules like this:
iptables -t nat -A PREROUTING -p tcp --source-port x -j DNAT --to-destination SIP0 --dport y -d RIP
iptables -t nat -A PREROUTING -p tcp --source-port x -j DNAT --to-destination SIP1 --dport y -d RIP
I think this won't work since when eth0 will fail, the 1st rule will always be matched by iptables and the packets will never reach destination.
I have found the answer myself: When an interface fails I run a script which will delete the corresponding iptables rules, and that's it.