Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

For this command lines:

sysctl net.ipv4.ip_forward=1

iptables -t nat -A PREROUTING -p tcp --dport port -j DNAT --to-destination ip:port

iptables -t nat -A POSTROUTING -j MASQUERADE

I can reroute to ip:port

But how do I use a DNS instead? For example:


share|improve this question

If you want to redirect DNS quries you can try this.

iptables -t nat -A PREROUTING -i ethX -p udp --dport 53 -j DNAT --to $(get lan_ipaddr)
iptables -t nat -A PREROUTING -i ethX -p tcp --dport 53 -j DNAT --to $(get lan_ipaddr)
iptables -t nat -L -v -n # shows nat table

and if you try to forward port 80 to another ip. Here is the rule and a example of it.

iptables -t nat -A PREROUTING -p tcp -i eth0 -d --dport 80 -j DNAT --to

Please let me know in case of queries or if it was the answer of your question.

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.