I have a router (with iptables support) with 2 WAN interfaces (wan0 and wan1) and I am trying to redirect calls of specific IPs (for ex: over second interface (wan1) using ip tables. Traffic is coming from single LAN interface (eth0). I tried to mark the network packets like this:

iptables -t mangle -I PREROUTING -d $PUBLIC_IP -p tcp --dports 80,443 -j MARK --set-mark 0x77

and then create a rule through UI of router based on markings. But no luck.

Can this be done using only iptables?

I am sorry I am not coming from networking field so any help appreciate.

Thanks in advance!

1 Answer 1


It sounds like you want to create a DNAT rule. Maybe something like:

iptables -t nat -A PREROUTING \
  -p tcp --dports 80,443 \
  -j DNAT --to-destination $NEW_IP
  • I solved my problem using static routes, but interested in DNAT rule you provided. So, this rule will forward complete traffic from ORIGINAL_IP to NEW_IP? This implies that the WAN IP is known? Commented Jul 11, 2023 at 9:27

You must log in to answer this question.

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