Warning: Be sure to have set aliases for the virtual ip adresses you want to configure. Otherwise Postfix will complain about not being able to bind to those interfaces!

Should work with Postfix >= 2.7!

Scenario

You have 3 domains managed by Postfix:

domain1.tld
domain2.tld
domain3.tld

You have 3 IPs with reverse DNS records set.

IP1: 10.20.30.40
Reverse DNS: domain1.tld

IP2: 10.20.30.50
Reverse DNS: domain2.tld

IP3: 10.20.30.60
Reverse DNS: domain3.tld

Hmm, what if you want to be able to not only receive mails on this domains?

You need to bind Postfix on a sender domain base to the 3 IPs listed above!

Otherwise most ISPs will mark your mails as spam (reverse DNS, SPF).

Final outgoing IP mapping:

SENDER: sally@domain1.tld -> DOMAIN: domain1.tld -> IFACE 10.20.30.40 -> receiver@target.tld
SENDER: bob@domain2.tld -> DOMAIN: domain2.tld -> IFACE 10.20.30.50 -> receiver@target.tld
SENDER: john@domain3.tld -> DOMAIN: domain3.tld -> IFACE 10.20.30.60  -> receiver@target.tld

Ready for takeoff?

Append bind/delivery settings as following to Postfix config if not already there, otherwise edit them to fit your settings.

# vi /etc/postfix/master.cf
out_domain1  unix -       -       n       -       -       smtp
   -o smtp_bind_address=10.20.30.40
   -o smtp_helo_name=domain1.tld
   -o syslog_name=postfix-customer-domain1.tld

out_domain2  unix -       -       n       -       -       smtp
   -o smtp_bind_address=10.20.30.50
   -o smtp_helo_name=domain2.tld
   -o syslog_name=postfix-customer-domain2.tld

out_domain3  unix -       -       n       -       -       smtp
   -o smtp_bind_address=10.20.30.60
   -o smtp_helo_name=domain3.tld
   -o syslog_name=postfix-customer-domain3.tld

Tell Postfix to deliver outgoing mails over different (v)IPs based on sender domain

# vi /etc/postfix/main.cf
# mask outgoing mails on a per domain to ip match base
sender_dependent_default_transport_maps = hash:/etc/postfix/sender_transport

Edit domain to customer (IP) mappings

# vi /etc/postfix/sender_transport
@domain1.tld    out_domain1:
@domain2.tld    out_domain2:
@domain3.tld    out_domain3:
# ...

Create Postfix readable hash db (/etc/postfix/sender_transport.db)

# postmap hash:/etc/postfix/sender_transport

Restart postfix to activate domain based mail sender IPs

# /etc/init.d/postfix restart

Benjamin Wiedmann

Benjamin Wiedmann is an IT Professional, Software Developer, Photograph and Musician. Read more...

More Posts - Website

Follow Me:
TwitterLinkedInGoogle Plus


Benjamin Wiedmann

Benjamin Wiedmann is an IT Professional, Software Developer, Photograph and Musician. Read more...

0 Comments

Leave a Reply

Avatar placeholder

This site uses Akismet to reduce spam. Learn how your comment data is processed.