How to rotate IPs on opensmtpd
I have been a postmaster for the most part of the last decade, and I have always preferred postfix as my preferred MTA. However, recently I started playing with opensmtpd, the default SMTP server in openBSD. It is available for linux as opensmtpd-portable package, so you can run it on linux as well. Installing the opensmtpd software on your machine is out of scope of this article.
Let's say you have two IPs 192.168.1.2
and 192.168.1.3
on interface eth0
and eth0:0
respectively. You want to send from both IPs, with hostname mta-alpha.example.com
from 192.168.1.2
and hostname mta-beta.example.com
from 192.168.1.3
.
You need to edit your smtpd.conf
this way:
listen on eth0
listen on eth0:0
table myips { 192.168.1.2 192.168.1.3}
table myhostnames {192.168.1.2=>mta-alpha.example.com, 192.168.1.3=>mta-beta.example.com}
accept for any relay source <myips> hostnames <myhostnames>
This opensmtpd setup will accept any email coming from localhost and relay them via both IPs. It will pick the IPs in roundrobin fashion, and set the heloname matching the IP when making the outgoing SMTP connection to destination MX server.
This doesn't sign your messages with DKIM, so you might want to insert a DKIM signer proxy there.