IP-address Round-Robin for Postifx

Here’s a short and pretty self-desctriptive recipe to make your Postfix to send outgoing messages from different IP-addresses switching them on a round-robin basis.

First of all, we’ll need the list of IP-addresses in our roundabout, let’s put them to the /etc/postfix/roundabout file:

Then we’ll need the script to add IP-address aliases to our network interface. Surely, you can add them to the operating system configuration, but I’d suggest you to keep them all to the same /etc/postfix/roundabout file, so let’s put it to the /root/bin/roundabout_aliases.sh file:

If we want this script to be invoked automatically when the network interface starts, let’s create or modify the /sbin/ifup-local script (if we have a CentOS/RedHat-based system):

And now, the last, but not ever least, let’s implement the little script to change the smtp_bind_address value in our /etc/postfix/postfix.conf configuration. Let’s call it /root/bin/roundabout-postfix.sh:

You can run this script by cron or when certain event happens (e.g., when the current IP-address has been blacklisted).

And don’t forget to add something like smtp_bind_address = 0.0.0.0 to the /etc/postfix/main.cf file before to run this script for the first time, in other case it won’t find the IP-address to be changed! 🙂

Leave a Reply

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