Postfix - outbound SMTP traffic going out wrong interface
This was a configuration problem in master.cf
. The configuration shown above (in my question) only sets smtp_bind_address
for inbound traffic, meaning for the listening daemons.
For outbound traffic, meaning when the postfix daemon sends mail to other servers, the following line in master.cf
must also have the bind address specified. In the default/sample master.cf
the line looks like this:
smtp unix - - y - - smtp
It's buried down below a lot of other parameters, easy to miss.
Change it to add the bind address with e.g.:
smtp unix - - y - - smtp
-o smtp_bind_address=10.8.0.9
Since I run multiple postfix daemons on the same server in order to serve multiple domains with separate public IPs and certificates, I changed mine to:
outbound_domain1.com unix - - y - - smtp
-o smtp_bind_address=10.8.0.8
-o smtp_helo_name=domain1.com
...and then added a line in /etc/postfix/sender_transport
to map this outbound daemon to the email domain it serves:
@domain1.com outbound_domain1.com
And of course you also have to tell postfix to use that transport map, in main.cf
:
sender_dependent_default_transport_maps = hash:/etc/postfix/sender_transport
And then run postmap
to generate the hash files that postfix uses for these lookups.