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 -p tcp --dport 443 -j DNAT --to-destination

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


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 -j DNAT --to-destination

  • 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 .