In a dedicated server with several containers behind NAT, I'm trying to route the output / outbound traffic from one of the containers through a specific virtual interface attached to the main physical interface. Both interfaces have public IPs assigned to them.

The chain would look as follows:

OpenVZ container ( > Host system (eth0:0; IP: > internet

as opposed to the current

OpenVZ container ( > Host system (eth0; IP: > internet

I believe this can be done with an iptables postrouting rule

  • Tried with 'route add -host dev eth0:0' but then the inbound routing is lost. – manchine May 16 '15 at 1:27

As it turned out, a simple postrouting rule did the trick.

iptables -t nat -A POSTROUTING -s '' -o eth0 -j SNAT --to

I also had to delete a bunch of MASQUERADE postrouting rules that were just creating a big mess.

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.