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.
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
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 email@example.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.