Home > Articles > Security > Network Security

Converting Sendmail to Postfix, Part Two: Configuring Postfix

This second article in a two-part series on using the mail server Postfix covers basic configuration and some advanced topics, including virtual domains and supporting external and mobile users.

The first article in this series described the advantages of using Postfix over the "Internet standard" mail transport agent—Sendmail. This article covers some basic configuration scenarios.

Basic Postfix Configuration

Postfix, as installed from source or distribution package, requires little if any changes to work on a computer that has a direct Internet connection. The Postfix development team has chosen a good set of defaults for all its parameters to help you through the process of installing and sending email securely and responsibly. Out of the proverbial box, it just works.

The fact that Postfix works without having to spend your next four weekends in your office curled up with a nice 1,200-page installation reference manual (volume 1 of 3, of course) does not mean that there are no settings to change. Contrary to that belief, there are more than 200 (217 at the time of this writing) individual settings that alter the behavior of the stock Postfix installation. This does not include third-party add-ons or patches.

The more you customize and specialize Postfix to mold to your environment, the more intimate you need to be with the configuration files. Luckily, they are heavily commented with examples.

The Postfix Frequently Asked Questions (FAQ) document has many examples, including mobile users who are intermittently connected to the Internet. This article is primarily concerned with converting clients over from common Sendmail configurations.

The default installation of Postfix should work the same as any vendor preinstalled version of Sendmail would. The other key Sendmail configurations are as follows:

  • Smart relay—A mail server responsible for sending and/or delivering email for an entire network of hosts. A smart relay may define alternative transports or routes for email within the organization. The additional email routing rules might override email delivery directions otherwise defined by DNS mail exchanger (MX) records, for example.

  • Null-client—A workstation configured for no local mail services; all email generated on a null-client is sent to the configured mail relay.

  • SMTP relay—Usually a firewall or DMZ server that passes email through to an internal smart relay mail server, but rejects unauthorized email and delivers no mail locally.

  • Supporting Virtual domains—The common configuration in which the mail server receives email for domain1.com and domain2.com, and so on.

  • Supporting Remote Users—Dynamically configured, remotely connected, remote branches all offer different problems, and should be addressed in the most efficient manner.

There are two configuration files, master.cf and main.cf, which primarily define how Postfix operates. From these two files, nearly all other (if any) configuration files, maps, and lookup tables are defined. Let's look at master.cf first.

master.cf

The file master.cf is the Postfix master process configuration file. It defines what and how local Postfix components are used, essentially defining the entire Postfix system. master.cf is composed of lines that describe how the Postfix component program should be run. Each line has eight fields that define the run-time parameters of that particular Postfix service. The fields, as with just about every aspect of configuring Postfix, are documented in the configuration file itself. The contents of a working master.cf are shown below:

# ==========================================================================
# service type private unpriv chroot wakeup maxproc command + args
#        (yes)  (yes)  (yes)  (never) (50)
# ==========================================================================
smtp   inet n    -    -    -    -    smtpd
pickup  fifo n    n    -    60   1    pickup
cleanup  unix -    -    -    -    0    cleanup
qmgr   fifo n    -    -    300   1    qmgr
rewrite  unix -    -    -    -    -    trivial-rewrite
bounce  unix -    -    -    -    0    bounce
defer   unix -    -    -    -    0    bounce
flush   unix -    -    -    1000?  0    flush
smtp   unix -    -    -    -    -    smtp
showq   unix n    -    -    -    -    showq
error   unix -    -    -    -    -    error
local   unix -    n    n    -    -    local
virtual  unix -    n    n    -    -    virtual
lmtp   unix -    -    n    -    -    lmtp

The process configuration file allows you to quickly add, remove, or change parameters and restraints of individual components of the Postfix system. Simply by commenting out a line, you can turn off a particular service. Likewise, either uncommenting a line or adding a new one, you can add a program or service used by Postfix.

If you developed a replacement component that you want to use in place of the stock Postfix component, you simply need to edit the command-line and arguments associated with the Postfix service. After you restart the Postfix service, you have effectively customized the Postfix system without compromising the rest of the programs or source.

main.cf

The main.cf file is the Global Postfix configuration file, which defines operational parameters for Postfix as you want it to run on your mail server. The format is very simple: Lines beginning with the pound (or hash) symbol are comments and are ignored, as are blank lines. Parameters are set by using the following pairs:

parameter = value

Lines that begin with whitespace are considered to be part of the previous line. This makes adding or removing additional parameter values quite nice because you can simply add or delete lines without worrying about affecting other values. The values themselves can reference other parameters by using the $other_parameter_name style.

The main.cf file is heavily commented, but contains only a small subset of the available parameters and possible values. Fuller listings and commented usage of the parameters, their values, and their effects are documented in the examples directory included in the source tar archive, and usually in the /usr/share/doc/postfix/examples directory in most GNU/Linux distributions.

Converting Your Sendmail Smart Relays

Smart relays know how to deliver email, either via DNS MX records, or via special transport routing maps. Smart relays then receive email from client machines, and will then route and/or deliver it as appropriate on the client's behalf. Smart relays may also deliver email locally for domains that it is responsible for, and make those mail spools available via NFS or POP/IMAP access.

Postfix has sane defaults for all parameters, so there is very little you need to configure to enable Postfix to start sending and receiving email for your organization. The snippet below just shows the settings in the main.cf that most administrators will set. The master.cf should not need to be changed at all.

/etc/postfix/main.cf:
  mydestination = $myhostname, localhost.$mydomain, $mydomain
  mydomain = domain.com
  myhostname = mail.$mydomain
  myorigin = $mydomain

Obviously you need to change the $mydomain parameter to match your own domain, and the $myhostname parameter to match your mail server's hostname. With those settings in place, you are well on your way to replacing Sendmail.

Converting your Sendmail Null-clients

A null-client is a machine that can only send mail. It receives no mail from the network, and it does not deliver any mail locally. A null-client typically uses POP/IMAP or NFS for mailbox access. The $myorigin parameter is what gets appended after the @ (at) symbol in the email address, so it shows where the email originated from. The default is $myhostname, however, we are not interested in having email sent to individual workstations. Appending the domain name removes the unnecessary information.

The important line here is relayhost because it instructs Postfix to use the DNS MX records to find the email relay for this workstation's domain.

/etc/postfix/main.cf:
  myorigin = $mydomain
  relayhost = $mydomain

If your organization has not properly set up DNS, and is not using MX records to help deliver email internally, you can explicitly set the $relayhost parameter to a fully qualified hostname.

Because the null-client does not receive email, and because it delivers no email locally, we can edit the master.cf to simplify things and reduce resource utilization locally:

/etc/postfix/master.cf:
  #smtp   inet n    -    -    -    -    smtpd
  #local   unix -    n    n    -    -    local

Comment out the above lines by placing a pound sign before the service name.

Configuring a Firewall Machine as a Relay Only

Running email on your firewall has the potential for trouble because it is an additional foothold you're providing to attackers. Smaller organizations that may not have the resources to set up a separate DMZ-hosted email relay can configure your firewall machine to act as a relay-only email "proxy" server. The idea is that for the outside world, the firewall will be your primary mail server. The firewall server will allow incoming SMTP connections from the Internet. However, the firewall will not delivery email locally; it will just spool it, and relay it to an internal email server.

The relaying of email to the internal email server is done through the transport_maps directive. This directive instructs Postfix to look at the transport map and do pattern matching based on the destination domain name. The transport file is quite simple:

/etc/postfix/transport:
  domain.com smtp:internal-mail.domain.com

After creating the transport file, issue the following command:

postmap hash:/etc/postfix/transport

The postmap command converts the text file into a keyed database file. The postmap command generally accepts hash, btree, and dbm as the database type. To find out what types of database lookup methods are supported by your Postfix installation, type the following:

postconf -m

Restricting the networks that may relay through the firewall, and what destinations are accepted or rejected is set through a combination of mynetworks, mydestination, and smtp_recipient_restrictions. The key value to add to the smtp_recipient_restrictions is reject_unauth_destination, which rejects messages that are not addressed properly to match your restrictions. A snippet of modified parameters in main.cf looks like this:

/etc/postfix/main.cf:
  myorigin = domain.com
  mydestination = domain.com
  mynetworks = 192.0.1.0/24 172.16.2.0/24
  transport_maps = hash:/etc/postfix/transport
  smtpd_recipient_restrictions = 
    permit_mynetworks 
    reject_unauth_destination
  local_transport = error:local mail delivery is disabled on this machine

The local_transport parameter enforces the fact that no email is delivered locally, so email to root@firewall.domain.com will be rejected with the error that local mail delivery is disabled. To enforce this policy decision, we will comment out the local delivery agent part of Postfix in the master.cf file:

/etc/postfix/master.cf:
  #local   unix -    n    n    -    -    local

Configuring a Postfix to be a Backup Email Server

A very common configuration for email servers is to be a backup mail exchanger (MX) for a primary mail server. This provides some reliability in an inherently unreliable Internet. Backup mail servers will receive email on behalf of other mail servers (thus, this is a form of relaying), but will not attempt to deliver the email locally.

Configuring Postfix to do backup MX mail forwarding is quite easy. First, make sure that your Postfix server is listed as a secondary MX server in DNS for the domain you are backing up. Then, add the domain you are backing up to the relay_domains parameter. Also ensure that check_relay_domains is listed as part of the smtpd_recipient_restrictions parameter.

/etc/postfix/main.cf:
  relay_domains = $mydestination
    backedupdomain.com
  smtpd_recipient_restrictions = 
    permit_mynetworks
    check_relay_domains

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020