5

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?

3 Answers 3

8

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.

0

if you use lxc or other virtualization technology, you redirect all traffic from port 445 to container's 1455.

The local request in Server A will not pass PREROUTING. The reason was addressed before. Local traffic will not access nat table, but if you use DNAT before, it only works for outer traffic to Server A, REDIRECT only worked for port forward, it can not be used as DNAT

1
  • Most of this is either factually incorrect or inaccurate. Please consider reworking this answer. Jun 13, 2014 at 16:25
-1

You should better read some manuals and docs.

Anyway brief chains description:

* “PREROUTING”: Packets will enter this chain before a routing decision is made.
* “INPUT”: Packet is going to be locally delivered. (N.B.: It does not have anything to do with processes having a socket open. Local delivery is controlled by the “local-delivery” routing table: `ip route show table local`.)
* “FORWARD”: All packets that have been routed and were not for local delivery will traverse this chain.
* “OUTPUT”: Packets sent from the machine itself will be visiting this chain.
* “POSTROUTING”: Routing decision has been made. Packets enter this chain just before handing them off to the hardware.

And take a look here:

Netfilter packet flow

Wikipedia

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .