How can I modify this iptables rule, so that all traffic which coming for this computer will be forwarded to

iptables -t nat -A PREROUTING -s -p tcp --dport 80 -j DNAT --to-destination

The problem is that I create the ip tables rule from ansible and created it in different environments, where the ip address ranges are different, but I want to forward the 80 port to always.


This rule will forward 80 port to

iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination

but this is not enough If you want to get back traffic then you should add this rule

iptables -t nat -A POSTROUTING -p tcp -d --dport 80 -j SNAT --to-source

where ip address is your iptables computer

These two rules have to solve the task.

| improve this answer | |
  • Thank you it is working, but I had an other issue. Here is my current iptbales pastebin.com/gasEMiqh and it has a nat too to the LXC containers. When I use the port forward in the containers I cant use the yum, so I cant install packages. How can I solve this problem? – PumpkinSeed Mar 26 '16 at 21:15
  • You have to configure yam to use anHTTP proxy To enable all yum operations to use a proxy server, specify the proxy server details in /etc/yum.conf. For additional information You can see this link centos.org/docs/5/html/yum/sn-yum-proxy-server.html – stambata Mar 27 '16 at 6:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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