Postfix Multi Instance Configuration

Configure Postfix Multi Instance to send through multiple IP addresses

A Postfix multi instance configuration can be very powerful when you need to scale up your outgoing email volume.

Once you get your postfix server running for a while, you may see that the bottleneck is not the hardware but the rate in which you are able to send out email to different providers.
Instead of wasting idle resources, we can just add an IP address to the server and setup Postfix to run in a multi instance configuration.This way, we can utilise what we already have and double the email throughput of the server.

There are other advantages for using this configuration but in this post I will focus on one.

Preparations

First, we need to add more IP addresses to our host. I’m going to skip this part as you know your server’s configuration better than me (NAT, routable addresses, Distribution).

Then we need a postfix server running.
If you don’t have one yet, use your package management software to install it.

Enabling Multi instance support

To enable the multi instance support, run the command:
postmulti -e init
And create the first instance:
postmulti -I postfix-2 -G outgoing -e create
-I Is the nickname for the instance. You can use the hostname or whatever you like.
-G is the group. In this post we are not using groups so just name it whatever you think describes it best. An example use for groups, is the ability to reload some of the instances while keeping the rest running.

The process will create new folder to hold both the configuration and the postfix mail queue. The structure is fairly simple but important to note for interacting with the instances:

  • Configuration files such as the main.cf files will be at /etc/instancename/ and in our example, under /etc/postfix-2/
  • The queue will be at /var/spool/instancename/ and in our example, under /var/spool/postfix-2/

Assigning an ip address to an instance

Once we have all of our instances set up, we can assign the different ip address.
Lets assume that we have two IP addresses available on the server – 192.168.50.44 192.168.50.45
For the main instance, which is configured in /etc/postfix, we will keep the localhost listener, and add a specific address:
Edit the /etc/postfix/main.cf file and look for the line:
inet_interfaces = all
And change it to:
inet_interfaces = localhost, 192.168.50.44
This means that the base postfix instance is now listening and sending through the localhost address and 192.168.50.44

For each of the other instances, edit the main.cf file located under /etc/instancename and specify which IP address will be in use. To follow with our example, edit the /etc/postfix-2/main.cf file and replace:
inet_interfaces = all
With:
inet_interfaces = 192.168.50.45

Don’t forget to restart the postfix service after making these change.

Interacting with the different instances

Warning – the flags in this section differ in case, -C != -c
Now that you have multiple postfix instances, you will have to adjust your interaction with the server.

Most of the postfix interaction commands will allow you to specify a configuration directory.
If you want to use the sendmail command and send an email through a specific instance, use the -C flag (uppercase).
sendmail -C /etc/postfix-2 recipient@emailaddress.com

The same goes to the postconf command. Use the -c flag to specify an instance configuration (lowercase).
postconf -c /etc/postfix-2 -e "inet_interfaces = 192.168.50.45"

The same goes to the rest of the command. Read the man pages before you run anything.

Destroying an instance

If you wish to remove an instance from the server, issue the commands:
postmulti -i postfix-2 -p stop
postmulti -i postfix-2 -e disable
postmulti -i postfix -e destroy

“Destroy” pretty dramatic.

  • Mike_McKoy

    Is this accurate for CENTOS 6.5?

  • Mike_McKoy

    I did not find “net_interfaces = all” in my main.cf. I did find “inet_interfaces = all”. Is there a difference?

    • YuvalO

      Looks like a mistake in the article.

      You are right, it is inet_interfaces.

      Thanks for the heads up

  • Mind Zuka

    you need to use separate ‘hostname’ for each instance, and if not then you will be traced as default host name, then resolved to one ip address

  • Andrea Ceccherini

    hello
    if i change :
    inet_interfaces = all
    to: inet_interfaces = localhost, 192.168.50.44, the SMTP port on 192.168.50.45 stop Working (telnet refused)

  • wakil

    hi i have configured the second postfix instances , the primary instance is working but the second instance started but not telnet with hostname ie telnet hostname 25
    it shows could not connect

  • mj23424

    Is there a way to tell the server to route mail to specific postfix instances based on the domain sending mail?

    Example:

    @domain1.com always routes to instance 1 with an ip of xxx.xxx.xxx.xxx

    @domain2.om always routes to instance 2 with an ip of xxx.xxx.xxx.xxx

Join my Online Postfix Class
Join my Online Postfix Class
I am working on a new Postfix training class that will be launching soon. The course includes:
  • Understanding the Logs files
  • Troubleshooting
  • Performance
  • Rate limiting
  • DKIM/DMARC/SPF
  • And much More

Powered by WordPress. Designed by Woo Themes