Oct 032009

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)

relayhost = example.com

Dns sections



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

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

example.com zone file

$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
b.ns IN A

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

a.mx IN A
b.mx IN A
c.mx IN A

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 Responses to “Postfix smtp outgoing load balancing”

Comments (4)
  1. If there’s additional interest in load balancing take a look at the affordables offered by companies like KEMP Technologies or the large enterprise ones offered by companies like F5 networks.


  2. 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?

  3. 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.

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

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>