Linux Postfix Configuration:

Configure a Linux eMail Server

Also see:

This tutorial covers the configuration of a Linux email server using the Postfix MTA (Mail Transfer Agent). Virtual hosting is also covered to allow one to perform email services for multiple domains. The following configuration is for recieving inbound email.

Related YoLinux Tutorials:

°Linux eMail server tutorial

°Sendmail server configuration

°Mailman Installation / Configuration

°Internet Security

°Security tools

°Linux Networking

°YoLinux Tutorials Index

Free Information Technology Magazines and Document Downloads
TradePub link image

Free Information Technology Software and Development Magazine Subscriptions and Document Downloads

Postfix Configuration:

Postfix is infinitely configurable to suit your needs. For large corporations and ISPs, Postfix can be configured to use a mySQL backend instead of using configuration files. Thus a quick insert or delete of a record can add users, domains, etc. This tutorial configures Postfix to receive email using local configuration files.

Postfix configuration file: /etc/postfix/

(Red Hat, Fedora, Suse and Ubuntu!)


# Common for all Postfix configurations:
smtpd_banner = $myhostname ESMTP $mail_name      - Mail RFC requirement. RHEL5: uncomment this line
biff = no                             - Turn off local user mail notification
mailbox_size_limit = 0                - Zero implies no limit
message_size_limit = 20480000         - Set a size limit on email
recipient_delimiter = +               - RHEL5: uncomment this line
append_dot_mydomain = no              - appending .domain is the MUA's job
                                        Can not send email to partial domain user@partialdomainname, 
                                        only full domains
mail_spool_directory = /var/mail      - RHEL5: uncomment this line

Allow no relay or outbound SMTP:

Add to file
relayhost =
mynetworks =
inet_interfaces = all          - Interfaces to listen on. Comma separated list eg. localhost, hostname

Receive email for local users: (multiple domains can be specified but an email sent to Michael is not distinguished between domains. One Michael for all domains.)

Add to file
myhostname =
mydomain =
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
# All domains listed in mydestination are subject to /etc/aliases mapping.
# Do not list domains to be used with virtual hosts!
mydestination = $mydomain $myhostname alternateName1 localhost.localdomain localhost

Virtual host:
(receive email for multiple domains. Users distinguished between domains. Email recipient is different than
Add this definition to support virtual hosts:

Add to file
# After edting file /etc/postfix/valias.txt
# run command: postmap /etc/postfix/valias.txt
# to create hash db file.
virtual_alias_maps = hash:/etc/postfix/valias.txt
# Use local unix account mailboxes for these domains
virtual_alias_domains = /etc/postfix/vhosts.txt

Add anti-SPAM measures:

Add to file
# Place all of the restrictions into the smtpd_recipient_restrictions:
smtpd_client_restrictions = reject_rbl_client
smtpd_helo_restrictions = reject_invalid_helo_hostname,
smtpd_sender_restrictions =
smtpd_helo_required = yes
strict_rfc821_envelopes = yes
disable_vrfy_command = yes
unknown_address_reject_code  = 554
unknown_hostname_reject_code = 554
unknown_client_reject_code   = 554

smtpd_recipient_restrictions =
#    permit_mynetworks,
#    permit_sasl_authenticated,
#    check_client_access hash:/etc/postfix/maps/access_client,
#    check_helo_access hash:/etc/postfix/maps/access_helo,
#    check_sender_access hash:/etc/postfix/maps/access_sender,
    check_sender_access hash:/etc/postfix/access_sender,
#    check_recipient_access hash:/etc/postfix/maps/access_recipient,
#    reject_rhsbl_client,  THIS SITE IS RETIRED
#    reject_rhsbl_sender,  THIS SITE IS RETIRED
#    reject_rbl_client,  THIS SITE IS RETIRED
# reject_rbl_client, THIS SITE IS RETIRED
#    reject_rbl_client,   THIS SITE IS RETIRED
#    reject_rbl_client,   THIS SITE IS RETIRED
#    reject_rbl_client,     THIS SITE IS RETIRED
#    reject_rbl_client, THIS SITE IS RETIRED

smtpd_data_restrictions =
  • SpamHaus combines three blackhole lists: Exploits block list (exploited systems):, Policy block list (non-MTA IP): and Spamhaus block list:, into one "".

Limit denial of service attacks:

Add to file
default_process_limit = 100
smtpd_client_connection_count_limit = 10
smtpd_client_connection_rate_limit = 30
header_size_limit = 51200
smtp_recipient_limit = 100

File: /etc/postfix/vhosts.txt
Domains listed here should NOT be listed with the "mydestination" directive.

File: /etc/postfix/valias.txt

This file maps email addresses to local user names: userjoe userjoseph userjoe
Upon creation or change, create the db file: postmap /etc/postfix/valias.txt
This creates the file /etc/postfix/valias.txt.db

File: /etc/postfix/access_sender       REJECT Domain MX in broadcast network      REJECT Domain MX in RFC 1918 private network     REJECT Domain MX in loopback network  REJECT Domain MX in link local network   REJECT Domain MX in RFC 1918 private network    REJECT Domain MX in TEST-NET network
192.168.0/16    REJECT Domain MX in RFC 1918 private network     REJECT Domain MX in class D multicast network     REJECT Domain MX in class E reserved network     REJECT Domain MX in reserved network
Generate database file "access_sender.db": postmap /etc/postfix/access_sender
Used by directive check_sender_access hash:/etc/postfix/access_sender

Other access lists:

Postfix debugging and diagnostics: Look in log files for error messages.
  • Red Hat: /var/log/maillog
  • Ubuntu: /var/log/mail.log

Postfix configuration tutorials:

More examples:

Postfix and Mailman email list server integration and configuration:

Postfix can be configured three different ways to interface with Mailman. The following uses the /etc/aliases file for this configuration. Requires the following configuration:

   alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
File: /etc/aliases
# regular aliases
info: user1
joe: user1
theadore: ted
# mailman aliases
mailman: "|/var/mailman/mail/mailman post mailman"
mailman-admin: "|/var/mailman/mail/mailman admin mailman"
mailman-bounces: "|/var/mailman/mail/mailman bounces mailman"
mailman-confirm: "|/var/mailman/mail/mailman confirm mailman"
mailman-join: "|/var/mailman/mail/mailman join mailman"
mailman-leave: "|/var/mailman/mail/mailman leave mailman"
mailman-owner: "|/var/mailman/mail/mailman owner mailman"
mailman-request: "|/var/mailman/mail/mailman request mailman"
mailman-subscribe: "|/var/mailman/mail/mailman subscribe mailman"
mailman-unsubscribe: "|/var/mailman/mail/mailman unsubscribe mailman"
megacorp: "|/var/mailman/mail/mailman post megacorp"
megacorp-admin: "|/var/mailman/mail/mailman admin megacorp"
megacorp-bounces: "|/var/mailman/mail/mailman bounces megacorp"
megacorp-confirm: "|/var/mailman/mail/mailman confirm megacorp"
megacorp-join: "|/var/mailman/mail/mailman join megacorp"
megacorp-leave: "|/var/mailman/mail/mailman leave megacorp"
megacorp-owner: "|/var/mailman/mail/mailman owner megacorp"
megacorp-request: "|/var/mailman/mail/mailman request megacorp"
megacorp-subscribe: "|/var/mailman/mail/mailman subscribe megacorp"
megacorp-unsubscribe: "|/var/mailman/mail/mailman unsubscribe megacorp"
These entries are generated by Mailman. See the YoLinux Mailman tutorial.

Links on Postfix and Mailman integration:
(Three different methodologies)

  1. Postfix-Mailman integration - GNU
  2. Use regular expression in configuration: example and tutorial.
    Example configuration including apache
  3. Python script to glue Postfix and Mailman together for domain "". This method does not require the creation of aliases.:

Postfix post-configuration and test:

Check if an open relay: (you do not want to be an open relay)



by Richard Blum
ISBN #0672321149, Sams
"Linux Email"
by Black, Koetter, Hilderbrandt, McDonald, Rusenko and Taylor.
ISBN #190481137X, Packt

I reviewed this book and found it to be a very complete discussion with examples of the installation, configuration, integration and use of Postfix, Courier POP/IMAP, SquirelMail, SpamAssassin, ClamAV and Cyrus SASL. It is concise and to the point. How to configure a Linux email server for the most popular and useful server configurations. This book is specific to the components listed and will get you up and running fast.
"Stopping Spam"
by Alan Schwartz, Debby Russell (Editor), Simson Garfinkel
ISBN #156592388X, O'Reilly and Associates
"Removing the Spam : Email Processing and Filtering"
by Geoff Mulligan
ISBN #0201379570, Addison-Wesley Networking Basics Series

    Bookmark and Share



Copyright © 2000 - 2013 by Greg Ippolito