Iptables for local connections

iptableslocalhost

On "Server A", I have a service running on port 1445.
"Server B" can connect to "Server A" on port 445 via the following rule:

iptables -t nat -A PREROUTING -d www.kunde.de -p tcp -m tcp –dport 445 -j REDIRECT –to-ports 1445

This does not work for connections initiated on "Server A", i.e. local connections. What can I do?

Best Answer

iptables -t nat -A OUTPUT -d www.kunde.de -p tcp -m tcp --dport 445 -j REDIRECT --to-ports 1445

Because locally originated packets go through OUTPUT, rather than through PREROUTING.