Redirect with iptables if destination port is not listened
- by PoltoS
I've a server listening on port 10000. But this server is running only in a special case (then some third service is available). Otherwise the port is not listened. Is it possible to redirect the client to another port if 10000 is not listening?
I see two solutions:
1) insert/remove iptables rules on server start/stop, but since the server may be killed, it may not insert the correct iptable redirect rule before dieing.
2) make a permanent userspace rule that checks if the port is listening and redirects the packet if not listened.
How to do 2) ? Do someone have recipes for ipq?
May be someone can suggest me a better way?
It is something like fallback redirect: I'll have thousand of clients with different ports (10000-11000) and if their instance of server is not running, whey should be redirected to some page explaining why they don't have and instance connected.