Linux – Postifix SMTP Load Balance

clusteremail-serverlinuxpostfixUbuntu

I want to load balance outbound emails between 3 post-fix gateways for sending mails only reason is to use multiple different source IPs to increase throughput & inbox delivery. Each gateway should receive an approximately equal amount of outbound messages.

How is it possible please suggest.

                    +----------> smtp A ---------> Internet
                    |                                  
clients --------> smtp lb -----> smtp B ---------> Internet
                    |                                  
                    +----------> smtp C ---------> Internet

Best Answer

One wonders what it is you are doing.

Nonetheless, the typical way to do this is by using round robin DNS for your SMTP server (define multiple A records for some DNS name, and specify that as the outbound SMTP server on whatever is originating emails, like an email client).

You could also make a load balancer out of another postfix server, because SMTP servers normally send emails to each other for forwarding. You should be able to do this simply by setting up multiple forwarders for it. If your emails are coming from a single source which caches DNS replies, this would be the more likely solution.

The way you do this is a bit of a hack: you set up a local DNS name which you configure as the relayhost in main.cf. Then, for that DNS name, configure multiple MX records with the same priority:

smtp-out IN MX 10 smtp-a.example.com.
smtp-out IN MX 10 smtp-b.example.com.
smtp-a.example.com. IN A 0.0.0.0
smtp-b.example.com. IN A 0.0.0.0