Postfix “loops back to theself” error on relay to another IP address on same machine

postfix

I'm trying to relay all mail for one domain "ourdomain.tld" from Postfix
running on port 2525 of one interface to another SMTP server running on port 25
of another interface on the same machine. However, when a message is received for
that domain, we're getting a "mail for loops back to myself" error.

Below are netstat and postconf, the contents of our /etc/postfix/transport file,
and the error that Postfix is logging. (The high bytes of each IP address are XXXed out.) Am I missing something obvious? Thanks –

# netstat -ln -A inet
Proto Recv-Q Send-Q Local Address Foreign Address State
...
tcp 0 0 XXX.XXX.138.209:25 0.0.0.0:* LISTEN
tcp 0 0 XXX.XXX.138.210:2525 0.0.0.0:* LISTEN

# postconf -d | grep mail_version
mail_version = 2.8.4

# postconf -n
alias_maps = hash:/etc/aliases
allow_mail_to_commands = alias,forward
bounce_queue_lifetime = 0
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
default_privs = nobody
default_process_limit = 200
html_directory = no
inet_interfaces = XXX.XXX.138.210
local_recipient_maps =
local_transport = error:local mail delivery is disabled
mail_owner = postfix
mailbox_size_limit = 0
mailq_path = /usr/bin/mailq
manpage_directory = /usr/local/man
message_size_limit = 10240000
mydestination =
mydomain = ourdomain.tld
myhostname = ourdomain.tld
mynetworks = XXX.XXX.119.0/24, XXX.XXX.138.0/24, XXX.XXX.136.128/25
myorigin = ourdomain.tld
newaliases_path = /usr/bin/newaliases
queue_directory = /var/spool/postfix
readme_directory = /etc/postfix
recipient_delimiter = +
relay_domains = ourdomain.tld
relay_recipient_maps =
sample_directory = /etc/postfix
sendmail_path = /usr/sbin/sendmail
setgid_group = postdrop
smtpd_authorized_verp_clients = $mynetworks
smtpd_recipient_limit = 10000
transport_maps = hash:/etc/postfix/transport
unknown_local_recipient_reject_code = 450

# cat /etc/postfix/transport
ourdomain.tld relay:[XXX.XXX.138.209]:25

# tail -f /var/log/maillog
...
Aug 2 23:58:36 va4 postfix/smtp[9846]: 9858A758404: to=<nicwolff@...
>, relay=XXX.XXX.138.209[XXX.XXX.138.209]:25, delay=1.1, delays=0.08/0.01/1/0,
dsn=5.4.6, status=bounced (mail for [XXX.XXX.138.209]:25 loops back to myself)

Best Answer

You can't do that. In your config it says mydomain = ourdomain.tld so you can't relay that domain to "outside" because you told Postfix that it (and only that instance) is responsible for that domain.

Set mydomain = localhost, localhost.localdomain and your problem should be fixed. To make sure, you should also set myhostname = something.ourdomain.tld

Related Topic