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 have a web server A and a postfix mail server B. They are all ubuntu server. For some reason B just connect with A and dosen't connect with internet, but A connect with internet. So I think I can set some iptable rules for A and B that will let A be B's router or bridge. I guess I must use DNAT rule but I cannot turn the idea to be ture. Can anybody help me?

share|improve this question
Internet --- (eth0) A (eth1) --- B

You can configure iptables for NAT translation, so packets from B can be routed through A, something like this:

iptables -A FORWARD -i eth1 -o eth0 -s <IP_of_B> -m state --state NEW -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Remember to enable IP forwarding with:

echo 1 > /proc/sys/net/ipv4/ip_forward
share|improve this answer
Your rules just include the data form B to A for the server A. What about A to B? – Yadun Sep 1 '11 at 9:02
The second line will do this. You can also insert -i eth0 -o eth1 for more clearly. – quanta Sep 1 '11 at 9:11

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.