Postfix smtp outgoing load balancing

I got good workaround for balancing smtp outgoing from postfix mailing list archives(not using expensive real load balancer). suppose we have 4 smtp servers for outgoing email, and we need to configure/load balance like this:

                                                         +------------+
                                                         |            |
                    +----------> smtp backend a -------->|            |
                    |                                    |            |
clients --------> smtp lb -----> smtp backend b -------->|  Intenet   |
                    |                                    |            |
                    +----------> smtp backend c -------->|            |
                                                         |            |
                                                         +------------+

Here’s the configuration :

Postfix section

main.cf (smtp lb/load balancer)

/etc/postfix/main.cf:
relayhost = example.com

Dns sections

named.conf

/etc/named.conf:

options {
        directory "/var/named/data";
};

zone "example.com" in {
        type master;
        file "example.com";
};

example.com zone file

/var/named/data/example.com
$TTL 2D;

@ IN SOA a.ns.example.com hostmaster.example.com (
            1            ; Serial
            10800           ; Refresh after 3 hours
            3600            ; Retry after 1 hour
            604800          ; Expire after 1 week
            3600 )          ; Minimum TTL of 1 hour
@ IN NS a.ns
@ IN NS b.ns
a.ns IN A 192.0.2.1
b.ns IN A 192.0.2.2

@ IN MX    0 a.mx
@ IN MX    0 b.mx
@ IN MX    0 c.mx

a.mx IN A 192.0.2.3
b.mx IN A 192.0.2.4
c.mx IN A 192.0.2.5

By default relayhost(in main.cf) will listing all available mx on example.com and randomly shuffles mx with equal preference(Postfix client makes a random selection between equal-preference MX hosts), in this case these mx are our smtp backend for balancing outgoing mail.

Source : postfix manual (relayhost)

Victor Duchovni (postfix-users mailing list)

4 Comments

  1. Dhanasekaran

    Hello,

    We have setup this similar setup in our server for email marketing. However, the email are bounced back with relay access is denied. We need a bounce back emails. Can you tell me how can we fix this?

  2. SnAIKerZ

    The postfix have a internal algorithm that per default randomize the order of equal-preference MX host addresses. Modifying the parameter “smtp_randomize_addresses” to “no” the postfix will use all mx host list sequentially.

    • sure, that should do the job done in round robin fashion 😀

Leave a Reply

Your email address will not be published. Required fields are marked *