Postfix SMTP Relay Configuration: Fixing “Host or Domain Not Found” Error for Local Domains


1 views

When setting up Postfix in a local network environment with an Exchange Server (mail.example.com), you might encounter this common delivery problem:

relay=none, delay=0.01, delays=0.01/0/0/0, dsn=4.3.5, status=deferred
(Host or domain name not found. Name service error for name=example.com
type=AAAA: Host found but no data record of requested type)

The error occurs because Postfix attempts to perform DNS lookups (both A and AAAA records) for the destination domain, even when sending to local domains within your network. This behavior is by design for security reasons, but needs proper configuration for internal mail routing.

For proper internal mail routing, you need to modify two key Postfix configuration files:

1. /etc/postfix/main.cf additions:

relay_domains = example.com
transport_maps = hash:/etc/postfix/transport

2. /etc/postfix/transport content:

example.com smtp:[mail.example.com]

After making changes, always run these commands:

postmap /etc/postfix/transport
postfix reload

For more complex environments, consider these additional configurations:

# For multiple domains
relay_domains = example.com, example2.com, $mydestination

# With authentication if required
example.com smtp:[mail.example.com]:submission

Use these commands to verify your setup:

postconf -n | grep relay
postmap -q example.com hash:/etc/postfix/transport
  • Ensure transport.db exists (created by postmap)
  • Verify permissions on transport files (usually root:postfix)
  • Check syslog for any errors after reload
  • Test with both internal and external domains

When setting up Postfix in a local network environment, you might encounter this cryptic error when trying to send emails to local domains:

relay=none, delay=0.01, delays=0.01/0/0/0, dsn=4.3.5, status=deferred 
(Host or domain name not found. Name service error for name=example.com
type=AAAA: Host found but no data record of requested type)

This occurs even when you can successfully send emails to external providers like Gmail or Yahoo. Let's break down why this happens and how to properly configure Postfix for local domain routing.

The error message reveals two important clues:

  • Postfix is performing DNS lookups (both A and AAAA records)
  • Your local Exchange server's domain isn't properly recognized as a local domain

By default, Postfix treats any domain not listed in mydestination or relay_domains as an external domain that requires DNS resolution. When it can't find proper MX records or A/AAAA records for your local domain, it fails with this error.

Here's the proper way to configure Postfix for local domain routing:

# In /etc/postfix/main.cf
relay_domains = example.com
transport_maps = hash:/etc/postfix/transport

# Then create/update /etc/postfix/transport
example.com smtp:[mail.example.com]

# After making changes
postmap /etc/postfix/transport
systemctl reload postfix

For more complex setups, consider these additional tweaks:

# To handle multiple domains
relay_domains = example.com, example.net, example.org

# For subdomain handling in transport maps
.example.com smtp:[mail.example.com]

# Disable DNS lookups for specific domains
smtp_skip_5xx_greeting = yes
smtp_skip_4xx_greeting = yes

Always verify your configuration with these commands:

# Check DNS resolution
dig example.com mx
dig example.com a
dig example.com aaaa

# Test Postfix routing
postmap -q example.com hash:/etc/postfix/transport
sendmail -bv user@example.com

To ensure this doesn't happen with other domains:

  • Always include local domains in either mydestination or relay_domains
  • Set up proper transport maps for any domains that need special routing
  • Consider using local_recipient_maps for additional recipient validation

Remember that the square brackets in smtp:[mail.example.com] tell Postfix to connect directly to that host without doing MX lookups, which is exactly what we want for local mail servers.