Postfix SMTP/TCP Service Error: Fixing “fatal: unknown service: smtp/tcp” in Mail Delivery


2 views

The error message "fatal: unknown service: smtp/tcp" typically occurs when Postfix cannot properly resolve the SMTP service in your system's configuration. This prevents outgoing mail delivery despite successful local queueing.

When troubleshooting this issue, verify these specific conditions in your setup:

# Check service resolution
$ grep smtp /etc/services

# Expected output should include:
smtp        25/tcp      mail
ssmtp       465/tcp     smtps

Two primary areas need attention in your Postfix configuration:

1. Master.cf Configuration

Ensure your master.cf contains the proper SMTP service definition:

smtp      unix  -       -       -       -       -       smtp
relay     unix  -       -       -       -       -       smtp

2. Network Service Resolution

Verify your name resolution services are properly configured:

# Check DNS resolution
$ dig smtp.gmail.com

# Verify nsswitch configuration
$ cat /etc/nsswitch.conf | grep hosts

Here's a step-by-step resolution process:

# 1. Stop Postfix
$ sudo systemctl stop postfix

# 2. Edit services file
$ sudo nano /etc/services
# Ensure these lines exist:
smtp           25/tcp          mail
smtp           25/udp          mail

# 3. Reconfigure Postfix
$ sudo postfix check
$ sudo postfix reload

# 4. Test SMTP resolution
$ telnet smtp.gmail.com 25

If the issue persists, try these advanced diagnostics:

# Check Postfix verbose logging
$ sudo postconf -n
$ sudo tail -f /var/log/mail.log

# Verify transport mapping
$ postconf -m | grep smtp

# Test with direct delivery
$ sendmail -v user@example.com << EOF
Subject: Test
Test message
EOF

Modern systems often need these additional settings:

# In main.cf
inet_protocols = ipv4
smtp_bind_address = 0.0.0.0
smtp_address_verify_target = rcpt

After implementing these changes, test your configuration:

$ echo "Test message" | mail -s "Test Subject" recipient@domain.com
$ mailq


The error message fatal: unknown service: smtp/tcp in Postfix typically indicates a fundamental configuration issue where the mail transfer agent cannot properly resolve or access the SMTP service. This occurs when Postfix attempts to deliver mail but fails to establish the necessary network connections.

First, verify your /etc/services file contains the correct SMTP entries:

smtp        25/tcp      mail
ssmtp       465/tcp     smtps

Then examine your master.cf configuration. The critical section should look like this:

smtp      inet  n       -       -       -       -       smtpd
smtp      unix  -       -       -       -       -       smtp

1. Service Definition Check:
Ensure your system's service database is properly configured. Run:

getent services smtp

This should return smtp 25/tcp. If not, you may need to rebuild your system's service database.

2. Master.cf Configuration:
Uncomment and activate the SMTP service in /etc/postfix/master.cf:

smtp      inet  n       -       -       -       -       smtpd
smtp      unix  -       -       -       -       -       smtp

After making changes, test your configuration:

postfix check
postfix reload
systemctl restart postfix

Then verify SMTP connectivity:

telnet localhost 25
EHLO localhost

Check Postfix logs in real-time:

tail -f /var/log/mail.log

For more detailed debugging, increase the log level in main.cf:

debug_peer_level = 2
debugger_command =

Here's a verified working main.cf snippet for basic SMTP operation:

myhostname = your.domain.com
mydomain = domain.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +

Remember to replace placeholder values with your actual domain information.

For external delivery, ensure your DNS records are properly configured:

dig MX your.domain.com
dig A your.domain.com

Your domain should have valid MX and A records pointing to your mail server.