Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a router with 1 network interface (eth0, public ip) and an alias for eth0:0, local ip

I want to redirect all incoming https (443) traffic to another server. I tried it with

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 443 -m conntrack --ctstate NEW -j DNAT --to-destination and it works. All traffic coming to my public ip's ssl port is redirected to

But the main problem is this; now all https traffic from my local lan to the internet is also redirected to that local ip, eg. and answers. How should I fix my configuration in order to make it work?

share|improve this question
up vote 1 down vote accepted

Just filter based on the destination address:

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 443 -d $PUBLIC_IP -m conntrack --ctstate NEW -j DNAT --to-destination

If the public IP is dynamic, you will need to add hooks to the DHCP client script to update this rule when your IP address changes. You may also use IP sets to change the IP address to check without changing your rule.

Another less perfect solution is to use the addrtype module. This modules makes a check on the routing table to determine what type of routing entry the address has. the LOCAL type can be used to check if this IP is the host's.

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 443 -m addrtype --dst-type LOCAL  -m conntrack --ctstate NEW -j DNAT --to-destination

Note that this solution also redirect connections to and or any IP address that your host have. You can exclude destination addresses by adding a simple ! -d match to the rule.

share|improve this answer
Thnx for your quick reply. How can I use -o with PREROUTING? At least iptables 1.4.12 does not accept it? But everything now works with --dst-type LOCAL :) – AnttiQ Aug 15 '13 at 9:42
@AnttiQ: Sorry i mean -d, not -o. Fixed. – BatchyX Aug 15 '13 at 12:13

You must log in to answer this question.

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