7

I've installed postfix 2.11.3 and we have multiple IP addresses on our server which we want to host two domains, isolated and running on their own IPs.

domain1  unix -       -       n       -       -       smtp
   -o smtp_bind_address=1.1.1.1
   -o smtp_helo_name=mail.abc.com
   -o syslog_name=postfix-mail.abc.com

domain2  unix -       -       n       -       -       smtp
   -o smtp_bind_address=2.2.2.2
   -o smtp_helo_name=mail.xyz.com
   -o syslog_name=postfix-mail.xyz.com

Following transporter /etc/postfix/sender_transport also defined in main.cf:

@abc.com    domain1:
@xyz.com    domain2:

After restarting postfix, it stopped listening on port 25:

[root@postfix-2.11.3]# telnet 1.1.1.1 25
Trying 1.1.1.1...
telnet: connect to address 1.1.1.1: Connection refused

But if I use following line in master.cf it listen on 25 and i can see banner if i telnet:

1.1.1.1:smtp inet  n - n - - smtpd -o myhostname=mail.abc.com 
2.2.2.2:smtp inet  n - n - - smtpd -o myhostname=mail.xyz.com

But I want to tell my mail server when you send out email use specific domain just like sender_transport

What i am doing wrong?

Notes:

I have removed following line from master.cf and replaced with above domain1 and domain2:

smtp      inet  n       -       n       -       -       smtpd
  • 1
    Any error lines in maillog after you restart postfix?? – masegaloeh Dec 8 '14 at 20:29
  • Yes, restarted and nothing in logs, I have very good knowledge of qmail mail and mail services so i have checked all basic stuff, I am new with postfix so bit confused, I think we need 1.1.1.1:smtp line without that it is not going to listen on 25 port, Now i have put both entries domain1/2 with ipaddress:smtp now it is listening on both IPs. but issue is when i am sending email from xyz.com it is default using 1.1.1.1 IP that means it is not looking into sender_transport file. – Satish Dec 9 '14 at 0:55
  • This is what i am trying to do but it didn't work wied.it/blog/… – Satish Dec 9 '14 at 1:18
  • Sorry guys! i have figured out what was the issue, we need both entries. x.x.x.x:smtp and domain1/2 before i was using either domain1 or smtp but i got the point.. sorry for hassle – Satish Dec 9 '14 at 4:11
14

Solution - Postfix version 2.7 or above required:

/etc/postfix/master.cf

#smtp      inet  n       -       n       -       -       smtpd
127.0.0.1:smtp inet  n     -       n       -       -       smtpd
      -o syslog_name=postfix-localhost
      -o smtp_helo_name=localhost
      -o smtp_bind_address=127.0.0.1
      -o myhostname=localhost

65.xxx.xxx.100:smtp inet  n     -       n       -       -       smtpd
      -o syslog_name=postfix-mail.abc.com
      -o smtp_helo_name=mail.abc.com
      -o smtp_bind_address=65.xxx.xxx.100
      -o myhostname=mail.abc.com

65.xxx.xxx.200:smtp inet  n     -       n       -       -       smtpd
      -o syslog_name=postfix-mail.xyz.com
      -o smtp_helo_name=mail.zyx.com
      -o smtp_bind_address=65.xxx.xxx.200
      -o myhostname=mail.xyz.com

abc-out  unix -       -       n       -       -       smtp
   -o smtp_bind_address=65.xxx.xxx.100
   -o smtp_helo_name=mail.abc.com
   -o syslog_name=postfix-mail.abc.com

xyz-out  unix -       -       n       -       -       smtp
   -o smtp_bind_address=65.xxx.xxx.200
   -o smtp_helo_name=mail.xyz.com
   -o syslog_name=postfix-mail.xyz.com

/etc/postfix/main.cf

sender_dependent_default_transport_maps = hash:/etc/postfix/sender_transport

/etc/postfix/sender_transport

# Use source IP - 65.xxx.xxx.100
@abc.com                abc-out:
@example.com            abc-out:

# Use source IP - 65.xxx.xxx.200 
@xyz.com                xyz-out:

Run command to generate hash db

postmap hash:/etc/postfix/sender_transport

Restart/Reload postfix

service postfix reload

Testing

[root@localhost ~]# telnet 65.xxx.xxx.200 25
Trying 65.xxx.xxx.200...
Connected to 65.xxx.xxx.200.
Escape character is '^]'.
220 mail.xyz.com ESMTP Postfix

Sending email test

[root@localhost ~]# telnet localhost 25
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 localhost ESMTP Postfix
helo localhost
250 localhost
mail from: spatel@xyz.com
250 2.1.0 Ok
rcpt to: spatel@gmail.com
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
Hello world!
.
250 2.0.0 Ok: queued as 93E708207BA

Got to gmail Inbox > Show Original

Delivered-To: spatel@gmail.com
Received: by 10.xxx.xxx.xxx with SMTP id w64csp782609qgd;
        Tue, 9 Dec 2014 09:35:57 -0800 (PST)
X-Received: by 10.xxx.xxx.xxx with SMTP id o28mr4132552yha.168.1418146557180;
        Tue, 09 Dec 2014 09:35:57 -0800 (PST)
Return-Path: <spatel@xyz.com>
Received: from mail.xyz.com ([65.xxx.xxx.200])
        by mx.google.com with ESMTPS id n10si743294ykc.114.2014.12.09.09.35.56
        for <spatel@gmail.com>
        (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Tue, 09 Dec 2014 09:35:56 -0800 (PST)
...
...
Message-Id: <20141209173720.93E708207BA@localhost.localdomain>
Date: Tue,  9 Dec 2014 12:37:11 -0500 (EST)
From: spatel@xyz.com

Hello world!

Voila!! see it used 65.xxx.xxx.200 IP address to sent out email..

Received: from mail.xyz.com ([65.xxx.xxx.200])
| improve this answer | |
  • I'm trying the same but hitting a configuration conflict with the default directives Ubuntu uses in master.cf. There is a conflicting smtp listener for the main IP address. How do you deactivate the default SMTP service? This is also for a system using amavis. – soze Aug 26 '15 at 4:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.