Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm using the Postfix mail server and I have 6 IPs available. I'd like to use another IP for the Postfix mail server for sending mail than the web server uses.

How can I do this? My postfix version is 2.3.3.

For example: main IP: 66.66.66.66 other IP: 66.66.66.67

share|improve this question

4 Answers 4

up vote 9 down vote accepted

You want smtp_bind_address=66.66.66.67 and inet_interfaces=all or inet_interfaces=eth(whatever) that 66.66.66.67 is on.

Make that change, then stop/start postfix. You can't just reload if you're changing inet_interfaces

share|improve this answer
    
I've tried the smtp_bind_address option but then my mail server doesn't send anymore mail. And I don't think inet_interfaces has to be changed since I don't want to receive mail on that server. Note, this IP is only used for sending mail. –  EarthMind Dec 8 '09 at 19:34
    
Please post your postconf -n so we can see what you're talking about. Anonymize IPs as private IPs (10.x.x.x, etc) and domains as example.(com|net|org|whatever) if you feel you need to. –  Bill Weiss Dec 8 '09 at 20:26
    
smtp_bind_address was the right way and I just had a delay in email delivery since the new IP I was using had no rDNS record. Kind thanks for your help. –  EarthMind Dec 8 '09 at 21:44

If you use the "smtp_bind_address" solution then your mail server will only listen on that specified IP address for incoming mail as well. The same thing applies to the "inet_interfaces" solution. This may not be the desired soltution if you want to listen for incoming mail on multiple IP addresses/interfaces.

My solution is better, because I suggest not to change the default "smtp_bind_address" and "inet_interfaces" settings, so your mail server will still listen for incoming mail on all IP addresses.

Only need to make a small change in your /etc/postfix/master.cf file.

Change this part:

smtp      unix  -       -       -       -       -       smtp
# When relaying mail as backup MX, disable fallback_relay to avoid MX loops
relay     unix  -       -       -       -       -       smtp
        -o smtp_fallback_relay=

to this:

smtp      unix  -       -       -       -       -       smtp
        -o smtp_bind_address=192.168.0.1
# When relaying mail as backup MX, disable fallback_relay to avoid MX loops
relay     unix  -       -       -       -       -       smtp
        -o smtp_bind_address=192.168.0.1
        -o smtp_fallback_relay=

Of course, instead of 192.168.0.1 you must use one of your IP addresses, the one you want to send your mail from.

Zoltan

share|improve this answer
    
I think that at the time I wanted the mail server to only listen to one IP address, for both incoming and outgoing email. But neverthless, I appreciate the extra info. Thanks. –  EarthMind Mar 19 '13 at 22:41

master.cf

Create different Interfaces. One for each domain:

rotate1  unix -       -       n       -       -       smtp
          -o syslog_name=postfix-rotate1
          -o smtp_helo_name=domainone.com.br
          -o smtp_bind_address=173.111.111.1

rotate2  unix -       -       n       -       -       smtp
          -o syslog_name=postfix-rotate2
          -o smtp_helo_name=domaintwo.com.br
          -o smtp_bind_address=173.111.111.2

main.cf

  1. Disable all other transport maps, i.e.: # transport_maps = xxxxx

  2. Enable dependent transport map (require postfix 2.7.x or later)

sender_dependent_default_transport_maps = mysql:/etc/postfix/config/transport_random_dependent.cf

transport_random_dependent.cf

Example:

user = postfix
password = mypassword
dbname = postfixdb
hosts = localhost
query = SELECT transport FROM transport_random WHERE domain = '%d' AND status='1' ORDER BY RAND() LIMIT 1

Table transport_random

Column "transport" = rotate1, rotate2, rotate3, rotate4 (etc)
Column "domain" = sender domains (replaced by %d)
Column "status" = boolean (0 or 1) if is enabled the transport.

The instruction "RAND() LIMIT 1" is necessary only if you want to use random transports for the same domain.

In example, you want to send from mydomain.com from 3 different IPs.

Then, you create 3 transports (rotate1, rotate2 and rotate3) with 3 different IPs, then set at mysql lines:

transport = rotate1 | domain = mydomain.com
transport = rotate2 | domain = mydomain.com
transport = rotate3 | domain = mydomain.com

Then, when postfix will randomize three different transports (rotate one to three) to send this emails.

share|improve this answer

Edit /etc/postfix/main.cf and make sure that the following line is present

inet_interfaces = 66.66.66.67, localhost

Then run "postfix reload"

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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