One of the most common tasks among postfix server system administrators is to configure the input/output IPs that a domain should use. This way, each domain works independently, avoiding reputational problems between them. For incoming connections, we will define the EHLO to present, and for outgoing connections, the IP to use.
Incoming connections:
First, we will configure the EHLO that should be displayed when a client connects to a specific IP. We will comment out the generic binding to make it specific for each IP.
#smtp unix - - n - - smtp
A.B.C.D:25 inet n - y - - smtpd -o myhostname=mail.DOMINIO1.com
E.F.G.H:25 inet n - y - - smtpd -o myhostname=mail.DOMINIO2.com
Outgoing connections:
We configure the IP that each of the domains should use.
out_DOMINIO1 unix - - n - - smtp -o myhostname=mail.DOMINIO1.com -o smtp_bind_address=A.B.C.D -o syslog_name=postfix-DOMINIO1
out_DOMINIO2 unix - - n - - smtp -o myhostname=mail.DOMINIO2.com -o smtp_bind_address=E.F.G.H -o syslog_name=postfix-DOMINIO2
sender_dependent_default_transport_maps = hash:/etc/postfix/sender_transport
@DOMINIO1.com out_DOMINIO1:
@DOMINIO2.com out_DOMINIO2:
/etc/init.d/postfix restart
If we choose to configure the transports to use through a database:
#sender_dependent_default_transport_maps = hash:/etc/postfix/sender_transport
sender_dependent_default_transport_maps = mysql:/etc/postfix/mysql/mysql_sender_transports.cf
We configure the query to be performed:
user = vmail
password = XXXXXXX
hosts = 127.0.0.1
dbname = postfix
query = SELECT sender_transport FROM sender_transports WHERE domain='%d'
We create the database and table:
CREATE DATABASE postfix;
CREATE TABLE sender_transports (
id int(11) unsigned NOT NULL auto_increment,
domain varchar(128) NOT NULL default '',
sender_transport varchar(128) NOT NULL default '',
PRIMARY KEY (id),
UNIQUE KEY domain (domain)
);
We create the MySQL user:
GRANT ALL PRIVILEGES ON postfix.* TO vmail@'localhost' IDENTIFIED BY 'XXXXXXX';
FLUSH PRIVILEGES;
We insert the domains:
INSERT INTO sender_transports (domain, sender_transport) VALUES ('DOMAIN1', 'out_DOMAIN1:');
INSERT INTO sender_transports (domain, sender_transport) VALUES ('DOMAIN2', 'out_DOMAIN2:');
We restart postfix:
We must keep in mind that the sender_dependent_default_transport_maps DO NOT apply to emails sent through redirects (alias).
If you connect directly with a client and send the email, the configuration of the sender_dependent_default_transport_maps is applied.
If an email is sent to an address with an alias and postfix forwards it to another, the sender_dependent_default_transport_maps are IGNORED.
If we need the aliases to go out through a specific IP, we must configure Postfix in multi-instance mode.