How to Change the Postfix Outbound IP Address (smtp_bind_address)
Set the IP address Postfix sends mail from on a multi-IP server, verify it, and optionally use a separate address per sender domain.
When a server has more than one IP address, Postfix does not pick the source address for outgoing mail itself; it leaves the choice to the operating system. Mail can then leave from an address whose reverse DNS does not match your mail host name, or that is missing from your SPF record, and receiving servers treat it as suspicious. This guide shows how to pin the outbound address with smtp_bind_address, for the whole server or per sender domain. It applies to Postfix on Ubuntu 24.04 and 22.04, Debian 12 and 13, and AlmaLinux 9, Rocky Linux 9 and CentOS Stream 9.
Requirements
- A working Postfix installation and a user with
sudorights. - The address you want to send from must already be configured on a network interface of the server.
- Control over the reverse DNS (PTR) record of that address, usually through your hosting control panel.
Choose the address
List the addresses on the server:
ip -4 addr show
ip -6 addr show
Pick the address whose PTR record resolves to your mail host name, and whose host name resolves back to the same address. You can check both directions with dig (package dnsutils on Debian and Ubuntu, bind-utils on the RHEL family):
dig +short -x 203.0.113.10
dig +short mail.example.com
The examples below use 203.0.113.10 for IPv4 and 2001:db8::10 for IPv6.
Set the outbound address for all mail
Set the parameter in /etc/postfix/main.cf. postconf -e edits the file for you and replaces an existing line instead of adding a duplicate:
sudo postconf -e "smtp_bind_address = 203.0.113.10"
If the server also sends over IPv6, set that address too. Otherwise mail to IPv6-capable destinations still leaves from a system-chosen IPv6 address:
sudo postconf -e "smtp_bind_address6 = 2001:db8::10"
Check the configuration for errors and reload Postfix:
sudo postfix check
sudo systemctl reload postfix
The old /etc/init.d/postfix restart command has been replaced by systemctl on all current distributions.
Verify the change
Confirm the active values:
postconf smtp_bind_address smtp_bind_address6
Then send a message to a mailbox on another provider and open its full headers. The topmost Received: line added by the receiving server shows the address your server connected from; it should be the one you configured. On your own server, watch the mail log during the test for warnings from the smtp process:
sudo journalctl -u 'postfix*' -f
Depending on the distribution, the same messages are also written to /var/log/mail.log (Debian, Ubuntu) or /var/log/maillog (RHEL family).
Fail instead of falling back (Postfix 3.7 and later)
If Postfix cannot bind to the configured address, for example because the address was removed from the interface, it logs a warning and by default delivers the mail anyway from whatever address the system chooses. Postfix 3.7 and later can defer the mail instead. Check your version:
postconf mail_version
If it is 3.7 or newer, enable enforcement and reload:
sudo postconf -e "smtp_bind_address_enforce = yes"
sudo systemctl reload postfix
On older versions the parameter is unknown, and Postfix warns about it as an unused parameter; leave it out there.
Use a different address per sender domain
To send one domain's mail from its own address, define an extra SMTP client in /etc/postfix/master.cf with its own bind address, and route that domain's senders to it. Add this entry at the end of master.cf; the continuation line must start with spaces:
out2 unix - - - - - smtp
-o smtp_bind_address=203.0.113.11
-o smtp_helo_name=mail.example.org
smtp_helo_name makes this client introduce itself with the host name that belongs to the second address. Next, map senders to the new transport in /etc/postfix/sender_transport:
@example.org out2:
Build the lookup table, tell Postfix to use it and reload:
sudo postmap /etc/postfix/sender_transport
sudo postconf -e "sender_dependent_default_transport_maps = hash:/etc/postfix/sender_transport"
sudo systemctl reload postfix
Mail with an envelope sender at example.org now leaves from 203.0.113.11; everything else keeps using the address from main.cf. Remember that the second address needs matching PTR and SPF records of its own.
Troubleshooting
- Mail still leaves from the old address: the destination was reached over IPv6 and
smtp_bind_address6is not set, or a transport inmaster.cfoverrides the value with its own-o smtp_bind_address=…. Check withpostconf -Mandpostconf -n. - Warnings about being unable to bind: the address is not configured on any interface. Compare with
ip addr show. - Deliveries time out after the change: the chosen address has no route to the internet (for example a private address). Postfix's documentation notes that binding to a fixed address can be a problem on multi-homed hosts where some destinations are reachable only through another interface.
Frequently asked questions
Why not set inet_interfaces to a single address instead?
That also works in a limited way: when inet_interfaces lists exactly one non-loopback IPv4 address and smtp_bind_address is unset, Postfix uses it as the source address. But inet_interfaces primarily controls where Postfix receives mail, and changing it requires stopping and starting Postfix. The Postfix documentation recommends leaving it at its default and setting the bind address explicitly.
Does this affect incoming mail?
No. smtp_bind_address only applies to the SMTP client, the part of Postfix that delivers mail to other servers. The addresses Postfix listens on are set by inet_interfaces and master.cf.
What else has to match the outbound address?
Three things: the PTR record of the address should resolve to your mail host name, that host name should resolve back to the address, and the address must be covered by the SPF record of every domain you send for. The name Postfix announces in the SMTP greeting is smtp_helo_name, which defaults to myhostname.
Can I rotate between several outbound addresses?
smtp_bind_address takes one address per SMTP client. You can define several clients in master.cf and assign them by sender, as shown above, but spreading mail across addresses to dodge reputation limits tends to hurt deliverability rather than help it.