Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 am able to port forward using following commands:

iptables -t nat -A PREROUTING -p tcp -d XXX.XXX.XXX.XXX --dport 80 -j DNAT --to

iptables -t nat -A POSTROUTING -d -j MASQUERADE

I wanted to use if it is possible to forward packets aimed at a domain name instead of an IP address like XXX.XXX.XXX.XXX.

For instance, can one do something like the following and make it work? Mine does not work!

iptables -t nat -A PREROUTING -p tcp -d XXX.XXX.XXX.XXX --dport 80 -j DNAT --to
iptables -t nat -A PREROUTING -p tcp -d --dport 80 -j DNAT --to

Please notice that the preceding commands should forward to different machines.

share|improve this question
possible duplicate of How to create an Iptables rule using domain name – mailq Nov 24 '11 at 13:18
Note: using DNS names with iptables is generally a very bad idea, even iptables man page states this. – Janne Pikkarainen Nov 24 '11 at 13:19

No it is not possible. Packets are never aimed at domain names at the TCP/IP level.

You'll need to use some sort of load balancer (apache with ProxyPass, for instance) if you need to redirect requests to another host/port.

share|improve this answer

No you can't do something like that. DNS names are not allowed in netfilter rules. They only apply on TCP/IP and ICMP levels.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.