how to use postfix as a mail gateway with multiple IPs

Run multiple Postfix daemons on different ports/IPs

cp -pr /etc/postfix /etc/postfix2
vim /etc/postfix2/master.cf and change
smtp inet n – n – – smtpd
to
27 inet n – n – – smtpd

mkdir /var/spool/postfix2 && chown root.postfix /var/spool/postfix2
mkdir -m 700 /var/lib/postfix2 && chown postfix.root /var/lib/postfix2

vim /etc/postfix/main.cf and add
inet_interfaces = 11.22.33.44
smtp_bind_address = 11.22.33.44

vim /etc/postfix2/main.cf and change
queue_directory = /var/spool/postfix2
data_directory = /var/lib/postfix2

and add
inet_interfaces = 55.66.77.88
smtp_bind_address = 55.66.77.88

also change any other setting, if necessary, like mynetworks or myorigin.

/etc/init.d/postfix restart
postfix -c /etc/postfix2 start
(use stop instead to stop it)

TO DO:
– make control scripts for postfix2 start/stop/restart
– make mailq for postfix2’s queue

BONUS:
* Use a load balancer to balance mails to all IPs
yum install haproxy

vim /etc/postfix/master.cf and change
smtp inet n – n – – smtpd
to
26 inet n – n – – smtpd

vim /etc/haproxy/haproxy.cfg and delete everything AFTER the defaults section and add

listen postfix 0.0.0.0:25
mode tcp
balance roundrobin
option tcplog
# rate-limit sessions 5 #useful if you want to limit the incoming mail inject rate from another gw to 5/second
# backlog 100000 #to be used in conjunction with rate-limit
server postfix 11.22.33.44:26
server postfix2 55.66.77.88:27