DEV Community

Janak Shrestha
Janak Shrestha

Posted on

Linux Postfix Troubleshooting

Introduction

Postfix is one of the most widely used Mail Transfer Agents (MTAs) in Linux environments. It is known for its security, performance, and reliability. However, like any complex service, Postfix can encounter configuration issues that prevent it from functioning correctly.

This guide covers a real-world troubleshooting scenario where the Postfix service on a mail server was failing due to duplicate configuration entries in the main configuration file. The issue caused mail delivery problems and prevented remote servers from connecting to the mail server.


Understanding the Problem

The Scenario

Users of a monitoring application reported issues with the company mail server. The Postfix service appeared to fail intermittently. The mail server was located in the Stork DC and used Postfix as its Mail Transfer Agent.

Symptoms Observed

When checking the Postfix service status, the following symptoms were present. The service showed as inactive when first checked. After starting, the service ran but generated numerous warnings in the logs. The configuration check command produced warnings about overriding entries. Remote connections to the mail server on port 25 failed.

Initial Diagnosis

The first step was to check the service status and configuration.

systemctl status postfix
Enter fullscreen mode Exit fullscreen mode

The output showed the service was inactive. After enabling and starting the service, warnings appeared in the logs.

postfix check
Enter fullscreen mode Exit fullscreen mode

This command revealed the root cause: warnings about overriding earlier entries in the configuration file.


Root Cause Analysis

Identifying the Duplicate Entries

The warnings pointed to a specific line in the Postfix configuration file. To identify all occurrences of the problematic parameter, the following command was used.

grep -n "inet_interfaces" /etc/postfix/main.cf
Enter fullscreen mode Exit fullscreen mode

The output revealed the issue clearly.

122:# The inet_interfaces parameter specifies the network interface
132:inet_interfaces = all
133:#inet_interfaces = $myhostname
134:#inet_interfaces = $myhostname, localhost
135:inet_interfaces = localhost
143:# the address list specified with the inet_interfaces parameter.
173:# receives mail on (see the inet_interfaces parameter).
Enter fullscreen mode Exit fullscreen mode

Understanding the Problem

There were two active inet_interfaces entries:

Line Entry Status
132 inet_interfaces = all Active
135 inet_interfaces = localhost Active

Because line 135 appeared later in the file, it overrode line 132. This meant Postfix was configured to listen only on the loopback interface (127.0.0.1) instead of all network interfaces.

Why This Causes Problems

When Postfix listens only on localhost, it can only receive connections from the local machine. Remote servers, monitoring applications, and other clients cannot connect to the mail server. This explains why the monitoring app users experienced issues.


The Solution

Step 1: Backup the Configuration

Before making any changes, always create a backup of the configuration file.

cp /etc/postfix/main.cf /etc/postfix/main.cf.bak
Enter fullscreen mode Exit fullscreen mode

Step 2: Fix the Duplicate Entry

Comment out or remove the duplicate inet_interfaces line. In this case, line 135 was commented out.

sed -i '135s/^inet_interfaces/#inet_interfaces/' /etc/postfix/main.cf
Enter fullscreen mode Exit fullscreen mode

Alternatively, the line could be removed entirely.

sed -i '/^inet_interfaces = localhost/d' /etc/postfix/main.cf
Enter fullscreen mode Exit fullscreen mode

Step 3: Verify the Fix

Confirm that only one active inet_interfaces entry remains.

grep -n "^inet_interfaces" /etc/postfix/main.cf
Enter fullscreen mode Exit fullscreen mode

Expected output:

132:inet_interfaces = all
Enter fullscreen mode Exit fullscreen mode

Step 4: Check Configuration

Run the Postfix configuration check to ensure there are no errors.

postfix check
Enter fullscreen mode Exit fullscreen mode

A successful check produces no output.

Step 5: Restart Postfix

Restart the service to apply the changes.

systemctl restart postfix
systemctl status postfix
Enter fullscreen mode Exit fullscreen mode

Step 6: Verify Listening Ports

Confirm that Postfix is now listening on all interfaces.

ss -tlnp | grep :25
Enter fullscreen mode Exit fullscreen mode

Expected output shows 0.0.0.0:25 and [::]:25, indicating all interfaces.


Verification and Results

Service Status After Fix

 postfix.service - Postfix Mail Transport Agent
     Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; preset: disabled)
     Active: active (running) since Thu 2026-09-17 16:53:47 UTC; 24ms ago
   Main PID: 9390 (master)
      Tasks: 3 (limit: 404516)
     Memory: 3.5M
     CGroup: /system.slice/postfix.service
             ├─9390 /usr/libexec/postfix/master -w
             ├─9391 pickup -l -t unix -u
             └─9392 qmgr -l -t unix -u
Enter fullscreen mode Exit fullscreen mode

Listening Ports After Fix

LISTEN 0 100 0.0.0.0:25 0.0.0.0:* users:(("master",pid=9390,fd=13))
LISTEN 0 100   [::]:25   [::]:* users:(("master",pid=9390,fd=14))
Enter fullscreen mode Exit fullscreen mode

Configuration Check After Fix

postfix check
Enter fullscreen mode Exit fullscreen mode

No output, indicating a clean configuration.

Comparison Table

Check Before After
Active inet_interfaces entries 2 1
postfix check warnings Yes No
Listening address 127.0.0.1:25 0.0.0.0:25
Remote connectivity Failed Working
Service status Warnings Clean

Understanding Postfix Configuration

The main.cf File

The /etc/postfix/main.cf file is the primary configuration file for Postfix. It contains parameters that control how Postfix operates. Each parameter is specified as parameter = value.

Duplicate Parameters

When a parameter appears multiple times, Postfix uses the last occurrence. However, it generates a warning about the earlier entry being overridden. This behavior is important to understand because it can lead to unexpected configurations.

The inet_interfaces Parameter

The inet_interfaces parameter specifies which network interfaces Postfix listens on. Common values include:

Value Meaning
all Listen on all interfaces
localhost Listen only on loopback (127.0.0.1)
127.0.0.1 Listen only on loopback
$myhostname Listen on the host's IP address
eth0 Listen on a specific interface

For a mail server that needs to receive mail from other servers, inet_interfaces = all is the correct setting.


Common Postfix Configuration Issues

Issue 1: Duplicate Parameters

Duplicate parameters cause warnings and unpredictable behavior. Use grep to find duplicates.

grep -n "^parameter_name" /etc/postfix/main.cf
Enter fullscreen mode Exit fullscreen mode

Remove duplicates by editing the file or using sed.

Issue 2: Incorrect Hostname

The myhostname parameter must be a fully qualified domain name.

myhostname = stmail01.stratos.xfusioncorp.com
Enter fullscreen mode Exit fullscreen mode

Verify with hostname -f and check /etc/hosts.

Issue 3: Missing Mail Directory

Postfix requires the mail directory to exist and have correct permissions.

mkdir -p /home/user/Maildir/{cur,new,tmp}
chown -R user:user /home/user/Maildir
Enter fullscreen mode Exit fullscreen mode

Issue 4: Port Conflicts

If port 25 is already in use, Postfix fails to start.

ss -tlnp | grep :25
Enter fullscreen mode Exit fullscreen mode

Identify and stop the conflicting service.

Issue 5: Permission Problems

Postfix requires specific permissions on its directories.

ls -la /var/spool/postfix/
ls -la /etc/postfix/
Enter fullscreen mode Exit fullscreen mode

Fix permissions if needed.


Best Practices for Postfix Configuration

Always Backup Before Changes

Create a backup of the configuration file before making changes.

cp /etc/postfix/main.cf /etc/postfix/main.cf.bak
Enter fullscreen mode Exit fullscreen mode

Use postfix check

Always run the configuration check after making changes.

postfix check
Enter fullscreen mode Exit fullscreen mode

Review Configuration Regularly

Periodically review the configuration for duplicate or outdated entries.

grep -c "^parameter_name" /etc/postfix/main.cf
Enter fullscreen mode Exit fullscreen mode

Test After Changes

Restart the service and verify it is running correctly.

systemctl restart postfix
systemctl status postfix
ss -tlnp | grep :25
Enter fullscreen mode Exit fullscreen mode

Monitor Logs

Regularly check Postfix logs for errors and warnings.

journalctl -u postfix -n 50
tail -f /var/log/maillog
Enter fullscreen mode Exit fullscreen mode

Document Changes

Maintain a record of configuration changes for troubleshooting and audit purposes.


Troubleshooting Workflow

Step 1: Check Service Status

systemctl status postfix
Enter fullscreen mode Exit fullscreen mode

Step 2: Check Configuration

postfix check
Enter fullscreen mode Exit fullscreen mode

Step 3: Check Logs

journalctl -u postfix -n 50
Enter fullscreen mode Exit fullscreen mode

Step 4: Identify Duplicate Parameters

grep -n "^parameter_name" /etc/postfix/main.cf
Enter fullscreen mode Exit fullscreen mode

Step 5: Fix the Configuration

Edit the file to remove duplicates or correct errors.

Step 6: Verify the Fix

postfix check
Enter fullscreen mode Exit fullscreen mode

Step 7: Restart the Service

systemctl restart postfix
Enter fullscreen mode Exit fullscreen mode

Step 8: Verify Listening Ports

ss -tlnp | grep :25
Enter fullscreen mode Exit fullscreen mode

Conclusion

Summary of the Fix

The Postfix service on the mail server was failing due to duplicate inet_interfaces entries in the configuration file. The last entry, inet_interfaces = localhost, was overriding the intended setting of inet_interfaces = all. This caused Postfix to listen only on the loopback interface, preventing remote connections.

The fix involved commenting out the duplicate entry, verifying the configuration, and restarting the service. After the fix, Postfix was listening on all interfaces, and the monitoring application could connect properly.

Key Takeaways

Duplicate configuration parameters in Postfix can cause unexpected behavior. The grep command is useful for identifying duplicates. The postfix check command validates the configuration. Always backup configuration files before making changes. Verify listening ports after restarting the service. Understanding the inet_interfaces parameter is essential for mail server configuration.

Final Configuration

inet_interfaces = all
Enter fullscreen mode Exit fullscreen mode

Final Service Status

Active: active (running)
Enter fullscreen mode Exit fullscreen mode

Final Listening Ports

LISTEN 0 100 0.0.0.0:25 0.0.0.0:*
LISTEN 0 100   [::]:25   [::]:*
Enter fullscreen mode Exit fullscreen mode

Additional Resources

Manual Pages

  • man postfix - Postfix documentation
  • man main.cf - Postfix configuration parameters
  • man postconf - Postfix configuration tool
  • man postfix-check - Configuration check

Related Topics

  • Postfix TLS/SSL configuration
  • Virtual domain configuration
  • Spam filtering with SpamAssassin
  • Mail queue management
  • Postfix logging and monitoring

Useful Commands

Command Purpose
postfix check Validate configuration
postconf -n Show non-default parameters
postconf -d Show default parameters
mailq Show mail queue
postsuper -d ALL Delete all queued mail

Top comments (0)