How to force postfix to use ip that is configured for domain

dkimdomain-name-systememailpostfixspf

I want to confirm to SPF and DKIM, this requires me to send email using the IP written in the DNS record of the domain

I have two domains example1.com and example2.com with two IPs 100.0.0.1 and 100.0.0.2 respectively.

How can I configure postfix to always use IP 100.0.0.1 when the send from address is xx@example1.com and the same to be true for the other domain.

When connecting to the SMTP transport I am using localhost, I know I can configure two postfix instances for each IP and then just connect to the right IP when sending depending on the domain, I would like to see if this can be avoided.

How can this be done?

Best Answer

May take some fiddling, but i think you can achieve this in the following way:

  • configure your original smtpd listener in master.cf to route mail where sender is from each respective domain to two new, local smtpd listeners
  • setup 2 additional smtpd listeners in master.cf that have their own main.cf files (eg. example1.main.cf and example2.main.cf) :http://www.postfix.org/master.5.html (in said master.cf file, you can override various settings for main.cf via the -o name=value mechanism)
  • configure the new main.cf files with appropriate outbound interface configurations and other related main.cf configs
Related Topic