How to make Postfix use another IP address?

Solution 1:

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

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

Solution 2:

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/ 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=
# When relaying mail as backup MX, disable fallback_relay to avoid MX loops
relay     unix  -       -       -       -       -       smtp
        -o smtp_bind_address=
        -o smtp_fallback_relay=

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


Solution 3:

Create different Interfaces. One for each domain:

rotate1  unix -       -       n       -       -       smtp
          -o syslog_name=postfix-rotate1
          -o smtp_bind_address=

rotate2  unix -       -       n       -       -       smtp
          -o syslog_name=postfix-rotate2
          -o smtp_bind_address=

  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/


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 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 =
transport = rotate2 | domain =
transport = rotate3 | domain =

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

Solution 4:

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

inet_interfaces =, localhost

Then run "postfix reload"