I have LXC container with mail server and "dedicated" IP address.
"Dedicated" means that 25 and 110 port of the IP address are forwarded to 25 and 110 port of the container. This is done with iptables.
Let assume internal address of the container is 192.168.0.5 and public address is 30.30.30.30.
Let also assume the server has one LAN adapter "eth0" with one main IP (30.30.30.1) and several additional IP's "eth0:0" is 30.30.30.30
When mail server sends email, the email is send from main IP of the server.
How can I change this behavior and make all outgoing traffic to be via "30.30.30.30"
I found a way to do it.
Here is the rule:
Important points are:
-I
instead of-A
eth0
instead ofeth0:0
Remember important thing, if you would like to have all changes every time that you reboot your server, you need to complete this rule on your /etc/network/interfaces and in eth0 section:
And you always have your changes ready when you reboot your server.