1

I have a laptop that forwards all the traffic from one interface to another.

I followed the instruction provided for different question, and it works.

net.ipv4.ip_forward = 1

and add the following rules to iptables
sudo iptables -t nat -A POSTROUTING --out-interface eth1 -j MASQUERADE  
sudo iptables -A FORWARD --in-interface eth0 -j ACCEPT

Now, I would like to set a rule for traffic matching a certain destination IP and port to be redirected to a local server. I tried something like:

iptables -t nat -I OUTPUT --src 0/0 --dst 55.55.55.55 -p tcp --dport 443 -j DNAT --to-destination 127.0.0.1:4433

Actually I tried a few others, but without success. At best, I get redirected only the traffic that is generated locally (and not the transit traffic).

What should I try next?

1 Answer 1

0

If you want to redirect traffic to local server then use PREROUTING instead of OUTPUT chain like

iptables -t nat -I PREROUTING -p tcp -m tcp -d 55.55.55.55/32 -j DNAT --to-destination 127.0.0.1

1
  • Using the REDIRECT target is probably better, that is explicitly for redirecting traffic to the local host.
    – wurtel
    Sep 24, 2019 at 10:06

You must log in to answer this question.

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