How to make Postfix use another IP address?

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


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


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


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.