Postfix 'load balance' sending IPs

I got a server with 8 IP addresses to use as a mail server (With PostFix). I want PostFix to rotate the IP and hostname for each message. I found the config parameter

smtp_bind_address = 1.2.3.4

(And there's another one I can't remember that does hostname) But that only lets me bind to one IP/hostname.

Example;
I have these IP's:

1.1.1.1 => mail1.mydomain.com
1.1.1.2 => mail2.mydomain.com
1.1.1.3 => mail3.mydomain.com
[etc]

The first message should be sent from 1.1.1.1, second from 1.1.1.2, third from 1.1.1.3 etc. so just round-robin balancing the avaliable IPs

Is this possible with Postfix?


Postfix can't do that, but you could use iptables' SNAT target in conjunction with the statistics module to rotate your addresses. Something like this should do:

iptables -t nat -A POSTROUTING -p tcp --dport 25 -d <your_dest_mailserver> -m statistic --mode nth --every 8 -j SNAT --to 1.1.1.1
iptables -t nat -A POSTROUTING -p tcp --dport 25 -d <your_dest_mailserver> -m statistic --mode nth --every 8 -j SNAT --to 1.1.1.2
[...]
iptables -t nat -A POSTROUTING -p tcp --dport 25 -d <your_dest_mailserver> -m statistic --mode nth --every 8 -j SNAT --to 1.1.1.8

Take a look at the "Sender reputation" section of the Postfix 2.7 release notes. You might be able to bodge up something from it.

Otherwise, this post from the Postfix mailing list contains a statement from Wietse Venema stating that it will never be supported in Postfix. I agree with him, too -- if a recipient has put limits in place, you shouldn't try and work around them. If that causes the recipient problems, that's their problem.