13
13
13
Electronic Mail
Servers
CERTIFICATION OBJECTIVES
L inux offers a number of alternative methods for handling incoming and outgoing e-mail.
RHEL 6 includes sendmail and Postfix for this purpose.Yes, it includes Dovecot, Fetchmail,
and Procmail as well, but since the RHCE objectives focus on services associated with the
Simple Mail Transfer Protocol (SMTP), this chapter focuses on sendmail and Postfix, as they are the
two supported services associated with SMTP.
The default RHEL 6 SMTP service is now Postfix. That service was first developed
in the late 1990s as an alternative to sendmail. It was designed to be easier to configure.
It’s feasible for most administrators to directly edit the associated configuration files.
Now that Red Hat has changed default SMTP services from sendmail to Postfix,
they’ve reached another milestone.
Despite Red Hat’s move toward Postfix, sendmail is perhaps still the most
common server for SMTP services. It was the default service through RHEL 5. Red
Hat still supports it for RHEL 6. Once it is installed and configured, sendmail can be
configured as an e-mail server for anything from an enterprise to a smart host for a
personal system, subject to the limitations of an ISP. RHEL includes the open-source
version of sendmail; the commercial version is the Sentrion Message Processing
Engine from the company known as Sendmail (with the capital S).
For the purpose of this chapter, both Postfix and sendmail were installed on the
physical host system. Smart host versions of each server were installed on the
server1.example.com system. Access tests were performed from the VMs configured
in Chapters 1 and 2, representing different external networks.
A number of alternatives to Postfix and sendmail are not covered in this book;
they include procmail, mail.local, exim, Cyrus IMAP, and uucp.
E-mail systems are heavily dependent on name resolution. While you could handle
name resolution through /etc/hosts on a small network, any mail system that requires
Internet access needs access to a fully functional DNS server. For spam protection
and more, it’s important to make sure that the system that intends to send an e-mail
is actually transmitting with the assigned IP address.
But that is only one component of how e-mail works, from transmission to
delivery. E-mail messages start with a mail user agent (MUA), a client system for
sending and receiving e-mail such as mutt, Evolution, or Thunderbird. With the
help of a Mail Submission Agent (MSA), such mail is normally sent to an MTA
such as Postfix or sendmail. A Mail Delivery Agent (MDA) such as Procmail works
locally to transfer e-mail from a server to an inbox folder. Procmail can also be used
to filter e-mail. Red Hat also supports additional MTA services such as Dovecot to
enable POP3 and/or IMAP (or the secure cousins, POP3s and IMAPs) to receive
e-mail.
SMTP, the Simple Mail Transfer Protocol, has become one of the most important
service protocols of the modern era. Much of the Internet-connected world lives and
dies by e-mail and relies on SMTP to deliver it. Like POP3 and IMAP, SMTP is a
protocol, a set of rules for transferring data used by various mail transfer agents.
Mail Server cyrus-imapd* Installs the Cyrus IMAP enterprise e-mail system
Packages (several packages); may require perl-Cyrus.
cyrus-sasl Adds the Cyrus implementation of the Simple
Authentication and Security Layer (SASL).
dovecot Supports both the IMAP and the POP incoming e-mail
protocols.
dovecot-mysql, dovecot-pgsql, Includes database back ends and related plugins for
dovecot-pigeonhole Dovecot.
mailman Supports e-mail discussion lists.
postfix Includes an alternative to sendmail.
sendmail Installs the most popular open-source mail server of the
same name.
sendmail-cf Adds a number of templates that you can use to generate
your sendmail configuration file; required to process
many sendmail configuration files.
spamassassin Includes the spam fighting package of the same name.
Now run the following alternatives command, with the --config switch, to select
the preferred MTA:
# alternatives --config mta
The command leads to the following output, which allows you to choose from
installed SMTP e-mail servers. Other SMTP services, if installed, would be included
in the list that follows:
There are 2 programs which provide 'mta'.
Selection Command
-----------------------------------------------
*+ 1 /usr/sbin/sendmail.sendmail
2 /usr/sbin/sendmail.postfix
When make a selection, alternatives changes the appropriate runlevel scripts for
each service, which can be confirmed with the following commands:
# chkconfig --list sendmail
# chkconfig --list postfix
In fact, the chkconfig command, when used to list the runlevels associated with
an inactive service, may return an error message (with a proposed solution) similar
to the following:
service sendmail supports chkconfig, but is not referenced in any runlevel (run
'chkconfig --add sendmail')
The alternatives command does not by itself stop or start a service. If you did not
stop the original service earlier, the daemon will still be running. In that case, you’d
have to use the kill command described in Chapter 9 to kill the undesired SMTP
service. And it’s important to have only one SMTP service running on a system.
Interactions between sendmail and Postfix would lead to errors.
In addition, you’d have to use the appropriate script in the /etc/init.d directory
(sendmail or postfix) to start the desired SMTP service.
one option is to make sure that such users don’t have a login shell. For example, the
following command can set up a user named tempworker on a local system without a
login shell:
# useradd tempworker -s /sbin/nologin
That tempworker user can then set up his own e-mail manager such as Evolution,
Thunderbird, or even Outlook Express to connect to networked Postfix or sendmail
SMTP services. Any attempts by that user to log in directly to the server are rejected.
Of course, access is limited to configured users, whether or not their accounts are
configured with a login shell. That’s configured courtesy of the Simple Authentication
and Security Layer (SASL). As implemented for RHEL 6, it’s based on the cyrus-sasl
package, as configured in the /etc/sasl2 directory. While that directory may include
different configuration files for Postfix (smtpd.conf) and sendmail (Sendmail.conf, yes,
that’s an uppercase S), both configuration files refer back to the same authentication
scheme with the following directive:
pwcheck_method:saslauthd
Mail Logging
Most log messages associated with SMTP services can be found in the /var/log/maillog
file. Messages that you might expect to see in this file relate to
The entry is in the same format as the commands in the /etc/sysconfig/iptables file.
The iptables service, when started, reads the contents of the /etc/sysconfig/iptables
file along with and files cited in the Custom Rules section. Just remember, when you
add a file as a custom rule, to make sure the Firewall Table option shown in Figure 13-2
refers to a filter, consistent with standard iptables-based firewall rules.
FIGURE 13-1
Custom Rules
FIGURE 13-2
Alternatively, you could edit the /etc/sysconfig/iptables file directly. But any
future use of the Firewall Configuration tool would overwrite such custom rules.
In general, SELinux is not an issue for SMTP services. Only one SELinux boolean
applies to the Postfix service, allow_postfix_local_write_mail_spool. As suggested by
the name, it allows the Postfix service to write e-mail files to user spools in the /var/
spool/postfix directory.
EXERCISE 13-1
Create Users Just for E-Mail
In this exercise, you will create three users on the local system, just so they can access
the local SMTP server. It is understood that additional configuration is required to
set up access or limits for these users on the Postfix or sendmail SMTP services. The
users are mailer1, mailer2, and mailer3.
1. Review the useradd command. Identify the switch associated with the default
login shell.
2. Review the contents of the /etc/passwd file. Find a shell not associated with
logins. It should be
/sbin/nologin
Configuration Files
The configuration files are stored in the /etc/postfix directory. The main configuration
file, main.cf, is somewhat simpler than the sendmail alternative, sendmail.cf. It’s still
complex, as it includes nearly 700 lines.
Except for the .cf files, any changes must first be processed into a database with
the postmap command. For example, if you’ve added limits to the access file, it can
be processed into a binary access.db file with the following command:
# postmap access
It’s best to reload most services, as that avoids kicking off currently connected
users. And that can avoid users who complain about lost e-mails. But watch the
output. It should include the following:
Reloading postfix: [ OK ]
Without that output, there may be a different kind of problem with Postfix.
Sometimes that problem can be addressed by restarting the service with the following
command:
# /etc/init.d/postfix restart
Patterns can be set up in a number of ways. As suggested by the man page, you
can limit users with patterns such as
[email protected]
specifically the lack of a dot at the end of the 192.168.100 and the beginning of the
example.org expressions. These expressions still are inclusive of all systems on the
192.168.100.0/24 network and the *.example.org domain.
192.168.122.50
server1.example.com
192.168.100
example.org
The simplest iteration is the following, which forwards e-mail sent to a local user
to a regular e-mail address:
michael [email protected]
For companies that use different domains, the following line would forward e-mail
directed to [email protected] to [email protected]. It would forward other
example.org e-mail addresses in a similar fashion.
@example.org @example.com
Don’t forget to process the resulting files into databases with the postmap canonical
and postmap generic commands. If you modify the relocated, transport, or the virtual
files in the /etc/postfix directory, apply the postmap command to those files as well.
Postfix includes writable data files in the following directory; it normally includes
a master.lock file with the PID of the Postfix daemon:
data_directory = /var/lib/postfix
As defined in the comments of the main.cf file, some files and directories should
be owned by the root administrative user; others should be owned by the specified
mail_owner. In the /etc/groups file, you can confirm that there’s a dedicated group
named postfix, which is also part of the group named mail.
mail_owner = postfix
While Postfix works for the local system “out of the box,” more has to be done to
get it working for a network. To that end, you’ll need to activate and modify the
following myhostname directive to point to the name of the local system. For example,
you might change the entry
#myhostname = host.domain.tld
to an alternative like
myhostname = server1.example.com
Normally, you’d just uncomment the following myorigin directive, to label e-mail
addresses coming from this Postfix server with an origination domain. In this case,
the origination domain is example.com:
myorigin = $mydomain
By default, the following active directive limits the scope of the Postfix service to
the local system.
#inet_interfaces = all
inet_interfaces = localhost
In most cases, you’d change the active directive so that Postfix listens on all
active network cards:
inet_interfaces = all
#inet_interfaces = localhost
Normally, Postfix listens on both IPv4 and IPv6 networks, based on the following
inet_protocols directive:
inet_protocols = all
The mydestination directive specifies the systems served by this Postfix server.
Based on the previous settings, the following default directive means that accepted
mail may be sent to the local system’s FQDN (server1.example.com), the localhost
address on the example.com network, and the localhost system:
mydestination = $myhostname, localhost.$mydomain, localhost
For a Postfix server configured for the local network, you should add the name
of the local domain, already assigned to the mydomain directive:
mydestination = $mydomain, $myhostname, localhost.$mydomain, localhost
In addition, Postfix includes a syntax checker in the basic daemon. Run the
following command to see if there are any fatal errors in the main.cf file:
# postfix check
FIGURE 13-3
Custom Postfix
settings, based
on /etc/postfix/
main.cf
While there are a number of additional directives available in this file, they’re
beyond the basic configuration associated with the RHCE objectives. When changes
are complete, you can and should process this into an appropriate database with the
newaliases command. As the /etc/aliases file works for both Postfix and sendmail,
the newaliases command can process the /etc/aliases file for both MTAs.
If IPv6 networking is enabled on the local system, the IPv4 loopback address
(127.0.0.1) would be replaced by the regular IPv6 loopback address (::1).
The quit command can be used to exit from this connection. But don’t quit yet.
The EHLO localhost command is important; the EHLO is the enhanced HELO
command, which introduces the basic parameters of an SMTP server.
EHLO localhost
250-maui.example.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
FIGURE 13-4
Directions to
set up Postfix
authentication
The directive that follows allows authentication from nonstandard clients such as
Microsoft Outlook Express:
broken_sasl_auth_clients = yes
This allows authenticated users, allows access from networks configured with the
mynetworks directive, and rejects destinations other than the Postfix server:
smtpd_recipient_restrictions = permit_sasl_authenticated,
permit_mynetworks, reject_unauth_destination
For smart hosts to work, you’ll need to make sure that e-mail messages intended
for users on the local system are properly forwarded. And that’s possible through the
aforementioned /etc/aliases file. At the least, you should configure e-mail intended for
the root administrative user as forwarded to a regular local user, with a line such as
root michael
EXERCISE 13-3
Switch Services
This exercise presumes you’ve installed and want to test the sendmail SMTP service.
If you’re set on Postfix, there is no need to run this exercise. It assumes that both the
sendmail and sendmail-cf packages are installed.
files are stored in the /etc/mail directory. As sendmail is quite complex, configuration
is normally done with the help of macros.
As with Postfix, the sendmail software as installed accepts e-mail only from the
local system. Based on an understanding of associated macro files, the configuration
changes required to modify sendmail to accept incoming e-mail from a network, and
to forward e-mail through a smart host are relatively simple.
If you already know sendmail, and just want to know what’s required to meet the
RHCE objectives for that SMTP service, jump ahead to the sections associated with
the /etc/mail/access, file, accepting incoming e-mail, and smart hosts.
If successful, you’ll see the following output (the second “reloading” is in lowercase):
Reloading sendmail: [ OK ]
reloading sm-client: [ OK ]
Without this output, you should assume that sendmail did not re-read the configuration
files, and other measures are required, such as a restart.
Configuration Files
The following is a brief description of the standard configuration files in the /etc/mail
directory. Additional files with a .db extension are database files processed from some
of these listed here:
■ access Supports access control. The default version of this file supports
access from the local computer. You can add host names or networks to this
list, with a message to REJECT with an error message, DISCARD without
an error message, or RELAY to accept and send the e-mail. It is one way to
configure host- and even user-based security.
■ aliasesdb-stamp Supports date checks of existing database files.
■ domaintable Allows mapping different domains. For example, if a company
is moving its users from mheducation.com to mcgraw-hill.com, people might
still send e-mails to addresses such as [email protected]. The
following line would forward that e-mail to [email protected].
mheducation.com mcgraw-hill.com
If you forget how spamassassin is used with sendmail, run the rpm -qi
spamassassin command. You’ll see it in the description.
■ statistic Collects statistics on sendmail usage in binary format. You can read
it with the mailstats command. Does not exist until the sendmail service
starts processing mail.
■ submit.cf The main outgoing sendmail configuration file.
■ submit.mc A macro that you can edit and then generate a new submit.cf file.
■ trusted-users Lists special users that can send e-mail without warnings.
■ virtusertable Supports e-mail forwarding; if some users from outside local
networks use the local sendmail server, this file supports e-mail forwarding
from those domains.
Some of these files require the other sendmail package, sendmail-cf. Use the
rpm -qa | grep sendmail command to confirm whether these packages are installed.
Many of these files are cited in the sendmail.mc file. For example, the following
directive incorporates /etc/mail/virtusertable in the default sendmail.mc
configuration file:
FEATURE(`virtusertable',`hash -o /etc/mail/virtusertable.db')dnl
You may notice several versions of these files with .db extensions. These are the
database files used by sendmail. When you edit files in the /etc/mail directory, the
/etc/mail/make command, described shortly, processes these files into the .db
databases.
There’s one more important file, /etc/aliases, already described earlier in this
chapter. It has the same functionality for both Postfix and sendmail. In other words,
it includes a list of forwarders on a local system, from system addresses to the root
account, or from one regular user account to another. The newalises command
processes this file for sendmail as well.
Each line in the file either starts or ends with the dnl, which is the functional
equivalent of the comment character. All information after the dnl is ignored by the
sendmail macro processor. If coupled with a divert(0)dnl, all information between
the two divert directives is ignored.
The comments that follow provide important directions; the make command in
the /etc/mail directory in fact processes all files in the /etc/mail directory:
dnl # This is the sendmail macro config file for m4. If you make changes to
dnl # /etc/mail/sendmail.mc, you will need to regenerate the
dnl # /etc/mail/sendmail.cf file by confirming that the sendmail-cf
dnl # package is installed and then performing a
dnl #
dnl # /etc/mail/make
The command that follows includes the noted c4.m4 macro processor, from the
sendmail-cf package:
include(`/usr/share/sendmail-cf/m4/cf.m4')dnl
The include directive instructs the make command to read the contents of the named
file and insert it at the current location in the output. The quotes in the sendmail.mc
file do not conform to standard English usage. This is how additional standard
configuration information is left out of the main sendmail.mc macro file.
Incidentally, quoted parameters start with a back quote mark (`) and end with
a single quote mark (‘).
The VERSIONID that follows provides a label for the current configuration:
VERSIONID(`setup for linux')dnl
The OSTYPE directive that follows specifies the configured operating system:
OSTYPE(`linux')dnl
The define directive sets files or enables possibly desirable features. Some examples
in sendmail.mc support a list of e-mail aliases in the ALIAS_FILE (/etc/aliases),
identify where procmail lives (PROCMAIL_MAILER_PATH), and set basic
authentication options (confAUTH_OPTIONS).
One useful option is to avoid advertising the version of sendmail in use, which
would otherwise be shown in e-mail message headers. If you activate the following
define feature, others don’t have to know that you’ve configured sendmail version
8.14.4.
dnl define(`confSMTP_LOGIN_MSG', `$j Sendmail; $b')dnl
The commented define directive for a SMART_HOST that follows would be the
simplest way to set up forwarding to a smart host, as discussed later in this chapter.
dnl define(`SMART_HOST', `smtp.your.provider')dnl
Most of the active define options that follow relate to the performance of the
sendmail service. The exceptions, shown next, support the use of Procmail for
filtering, enable /etc/aliases for substitute e-mail addresses, and require
authentication to receive e-mail:
define(`PROCMAIL_MAILER_PATH', `/usr/bin/procmail')dnl
define(`ALIAS_FILE', `/etc/aliases')dnl
define(`confAUTH_OPTIONS', `A')dnl
The problem with the last of these define directives is that it allows plain text
authentication. Like the Telnet service, it allows people to send their usernames and
passwords over the network in clear text, where anyone who is listening can read
that authentication information. Clear text may be appropriate for initial tests and
generally conforms to the “basic operation” concept associated with the RHCE
objectives. However, for a sendmail service that requires some form of encryption,
you could substitute the following directive, which is commented out by default:
dnl define(`confAUTH_OPTIONS', `A p')dnl
The define directive that follows, if activated, would support the use of LDAP
authentication:
dnl define(`confDONT_BLAME_SENDMAIL', `groupreadablekeyfile')dnl
The define directives that follow relate to sendmail behavior for message delays
and do not affect basic configuration. The only active directive shown disables timeouts
when the server waits for an identification (IDENT) query.
dnl define(`confTO_QUEUEWARN', `4h')dnl
dnl define(`confTO_QUEUERETURN', `5d')dnl
dnl define(`confQUEUE_LA', `12')dnl
dnl define(`confREFUSE_LA', `18')dnl
define(`confTO_IDENT', `0')dnl
dnl FEATURE(delay_checks)dnl
The following options are prerequisites for host-based security, as they look to the
/etc/mail/access file for (allowed and) blacklisted users, systems, and even networks:
FEATURE(`access_db', `hash -T<TMPF> -o /etc/mail/access.db')dnl
FEATURE(`blacklist_recipients')dnl
If the root user tries to send e-mail through this SMTP server, the following
option requires that user’s full e-mail address:
EXPOSED_USER(`root')dnl
No additional directives are required in the sendmail.mc file to support access from
other systems on a network. However, security also depends on the /etc/mail/access
file, which also by default limits access to the localhost system.
To configure sendmail on the aforementioned submission port 587, you’d activate
the following directive:
dnl DAEMON_OPTIONS(`Port=submission, Name=MSA, M=Ea')dnl
If you’ve compiled the previously described TLS certificates, you can activate the
following directive to listen for secure SMTP connections on port 465:
dnl DAEMON_OPTIONS(`Port=smtps, Name=TLSMTA, M=s')dnl
For IPv6 networking, the following directive would listen to only the localhost
system:
dnl DAEMON_OPTIONS(`port=smtp,Addr=::1, Name=MTA-v6, Family=inet6')dnl
Alternatively, the following directive listens for both IPv4 and IPv6 traffic:
dnl DAEMON_OPTIONS(`Name=MTA-v4, Family=inet, Name=MTA-v6, Family=inet6')
when a reverse IP address search does not find the associated domain name. However,
if reliable DNS service is available, deactivating this option can reduce spam.
FEATURE(`accept_unresolvable_domains')dnl
If active, the following directive accepts the use of MX records from DNS servers
for the locations of remote e-mail servers:
dnl FEATURE(`relay_based_on_MX')dnl
The following directive is needed to make sure the sendmail service accepts
e-mail from local users:
LOCAL_DOMAIN(`localhost.localdomain')dnl
If you want to substitute a different domain for e-mail addresses, the following
directives, if active, specify a substitute:
dnl MASQUERADE_AS(`mydomain.com')dnl
dnl FEATURE(masquerade_envelope)dnl
dnl FEATURE(masquerade_entire_domain)dnl
The masquerading can be extended. The following directives, if active, would get
sendmail to substitute the MASQUERADE_AS domain for the localhost,
localhost.localdomain, mydomainalias.com, and mydomain.lan domain names.
dnl MASQUERADE_DOMAIN(localhost)dnl
dnl MASQUERADE_DOMAIN(localhost.localdomain)dnl
dnl MASQUERADE_DOMAIN(mydomainalias.com)dnl
dnl MASQUERADE_DOMAIN(mydomain.lan)dnl
But NIS is not secure. It just so happens that for RHEL 6, Red Hat has removed NIS
from its exam objectives.
If the local network is set up to use only IPv6 addressing, you would change the
last line in this file from
FEATURE(`msp', `[127.0.0.1]')dnl
to
FEATURE(`msp', `[IPv6:::1]')dnl
You can allow other computers to use your sendmail server by commenting out
this line. As described earlier, this requires a dnl directive in front, as shown:
dnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl
Next, if reliable DNS access is available, comment out the FEATURE directive
that allows the sendmail service to accept_unresolvable_domains. This action,
which requires verification of sender e-mail addresses, can help block spammers.
A spammer may fake his domain. Users from “unresolvable domains” aren’t allowed
access to this service, unless the accept_unresolvable_domains option is active, who
use just an IP address, or spammers who fake their domain name to hide themselves:
dnl FEATURE(`accept_unresolvable_domains')dnl
But that’s not enough. To allow remote system access to the local sendmail server,
you’ll need to add their names or IP addresses to the /etc/mail/access file. For
example, to allow access to the 192.168.122.0 domain, you’d add the following line
to that file:
Connect:192.168.122 RELAY
Watch the notation; unlike with other services, there is no dot (.) at the end of the
address. It covers all computers on the 192.168.122.0 network. Alternatively, you
could designate the example.com domain or a specific computer name or IP address.
Back up the current sendmail.cf file. Then you can generate a new sendmail.cf
file, process the other files in /etc/mail, and restart sendmail services with the
following command:
# /etc/mail/make
Now you can reconfigure e-mail clients such as Mozilla Thunderbird, Novell
Evolution, or even Microsoft Outlook Express to send outgoing e-mail through the
newly configured sendmail server. You’ll need to set the sendmail computer domain
name or IP address as the SMTP outgoing mail server.
If the remote smart host is smtp.example.org, you’d activate the directive as follows:
define(`SMART_HOST', `smtp.example.org')dnl
this service should be listening on port 25. In that case, a telnet localhost 25
command should return something similar to the following messages:
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 server1.example.com ESMTP Sendmail 8.14.4/8.14.4; Wed, 23 Feb 2011 16:58:20
-0800
The first connection refused message confirms that the sendmail configuration
file does not normally listen to IPv6 networking. To set up sendmail.mc for both
IPv4 and IPv6 beyond the localhost system, deactivate the following directive (by
adding the dnl in front):
dnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl
But that’s required only if IPv6 networking is required, which is not always the
case. If only IPv4 networking is required, comment out this directive as well.
CERTIFICATION SUMMARY
Red Hat includes two servers associated with the SMTP protocol: Postfix and
sendmail. Red Hat has switched default SMTP services between RHEL 5 and RHEL
6; it is now Postfix. Whichever SMTP service you select, it’s just one part of the
hierarchy of services for e-mail. Both Postfix and sendmail are part of the “E-mail
server” package group. If you want to switch between SMTP services, the
alternatives --config mta command can help. Mail log information can be found in
the /var/log/maillog file. You can test the current status of both SMTP services from
the local system with the telnet localhost 25 command.
Postfix is somewhat easier to configure than sendmail. Different Postfix
configuration files can be found in the /etc/postfix directory. User and host limits
can be configured in the access file. Several other files relate to redirected or
renamed e-mail accounts or domains. You’ll need to modify several Postfix
configuration directives in the /etc/postfix/main.cf file, including myhostname,
mydomain, myorigin, inet_interfaces, and mynetworks. The relayhost directive
can help configure forwarding to a smart host. If you need to configure Postfix
authentication, refer to additional directives in the /usr/share/doc/postfix-2.6.6
directory, in the README-Postfix-SASL-RedHat.txt file.
The sendmail service may still be the most popular SMTP server on the Internet.
It has configuration files in the /etc/mail directory. The two main configuration files
are: sendmail.cf and submit.cf. You can configure these files through macros
configured in the sendmail.mc and submit.mc files. You can configure user- and host-
based security with the help of the /etc/mail/access file. The sendmail.mc file
includes a commented example directive to help you configure a connection to a
remote smart host.
✓ TWO-MINUTE DRILL
Here are some of the key points from the certification objectives in Chapter 13.
Self Test 35
SELF TEST
The following questions will help measure your understanding of the material presented in this
chapter. As no multiple-choice questions appear on the Red Hat exams, no multiple-choice questions
appear in this book. These questions exclusively test your understanding of the chapter. It is okay if
you have another way of performing a task. Getting results, not memorizing trivia, is what counts on
the Red Hat exams. There may be more than one answer to many of the questions.
_____________________________________________________________
4. If you use /etc/aliases for forwarding e-mail, what command processes these files into an
appropriate database file for Postfix?
_____________________________________________________________
5. What file supports limits on hosts that can connect to Postfix?
_____________________________________________________________
6. What directive in the main.cf file is used to specify the domain served by the Postfix server?
_____________________________________________________________
7. What directive in the main.cf file is used to specify the IP address network served by the
Postfix server?
_____________________________________________________________
8. In what directory can you find documentation associated with the Postfix server?
_____________________________________________________________
LAB QUESTIONS
Several of these labs involve configuration exercises. You should do these exercises on test machines
only. It’s assumed that you’re running these exercises on virtual machines such as KVM. For this
chapter, it’s also assumed that you may be changing the configuration of a physical host system for
such virtual machines.
Red Hat presents its exams electronically. For that reason, the labs in this and future chapters
are available from the CD that accompanies the book, in the Chapter13/ subdirectory. In case you
haven’t yet set up RHEL 6 on a system, refer to Chapter 1 for installation instructions.
The answers for each lab follow the Self Test answers for the fill-in-the-blank questions.
4. Forwarding e-mail addresses for both sendmail and Postfix are normally stored in /etc/aliases.
Make sure to process these files into appropriate databases; for /etc/aliases, the database is
updated with the newaliases command.
5. The file that supports limits on hosts that can connect to Postfix is /etc/postfix/access.
6. The directive in the main.cf file that is used to specify the domain served by the Postfix server
is mydomain.
7. The directive in the main.cf file is used to specify the IP address network served by the Postfix
server is mynetworks.
8. You find documentation associated with the Postfix server in the /usr/share/doc/postfix-2.6.6
directory.
LAB ANSWERS
For most of these labs, you may be using an e-mail client like mutt. To send an e-mail to say user
michael@localhost, take the following steps:
1. Run the mutt michael@localhost command. The To: michael@localhost message should appear.
2. Press ENTER. At the Subject: prompt, enter an appropriate test subject name and press ENTER.
3. You’re taken to a blank screen in the vi editor. Use commands appropriate to that editor to
a screen similar to that shown in Figure 13-5.
13. From the screen shown in Figure 13-5, press y to send the noted message.
In addition, you may be verifying e-mail receipt in files a username file in the /var/spool/mail direc-
tory. Normally, such e-mail can be reviewed from within a user account with the mail command. In
addition, you may be verifying access to a running SMTP server with the telnet ip_address 25 com-
mand, where ip_address is the IP address of the SMTP server.
After making a configuration change, don’t forget to process the file appropriately. For Postfix, the
postmap filename command processes the file. For sendmail, the /etc/mail/make script processes the
file. For the common /etc/aliases file, the newaliases command processes the file. And don’t forget to
make sure the service actually re-reads the new configuration files.
Lab 1
In Postfix, to disable local-only access in the /etc/postfix/main.cf file, change the inet_interfaces
directive to accept all connections:
inet_interfaces = all
FIGURE 13-5
Self Test 39
But to meet the requirements of the lab, you’ll want to retain the default value of that directive:
inet_interfaces = localhost
Make sure Postfix is active (and any alternative mail servers such as sendmail are not).
In general, to verify authentication on an SMTP server, connect from the local system with the
telnet localhost 25 command. When you see a message similar to
220 maui.example.com ESMTP Postfix
Depending on the configuration, you should see messages similar to the following:
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
To verify receipt of e-mail in a user account, log in to that account, or at least verify the time stamp
associated with the username in the /var/mail directory. To make sure e-mail directed to the root user
is redirected to a regular user account, you’d add a line like the following to the /etc/aliases file:
root: michael
Given the wording for the question, any standard user account would be acceptable. Of course, to
implement this change, you’ll have to run the newaliases command, which processes this file into the
/etc/aliases.db file.
To make sure this works, you’ll want to use a command line client such as mutt or even mail as
defined in Chapter 2. For example, if you send a test e-mail to the local root user, the message should
be received by user michael (or whomever is configured in the /etc/aliases file to receive e-mail for-
warded from the root user).
Lab 2
To enable access from more than just the localhost, you’ll need to modify the inet_interfaces directive
in /etc/postfix/main.cf to
inet_interfaces = all
The next job is to limit access to a specific network, in this case, example.com. While there are
options in /etc/postfix files, perhaps the most efficient way to limit access to a specific network is with
an appropriate iptables-based firewall rule. For example, the following custom rule would limit access
to TCP port 25 to systems on the given IP address network. The network shown is based on the origi-
nally defined configuration for example.com, the 192.168.122.0/24 network:
-A INPUT -m state --state NEW -m tcp -p tcp -s 192.168.122.0/24 --dport 25 -j
ACCEPT
In addition, you’ll need to set up this network in the /etc/postfix/access file with a rule like the
following:
192.168.122 OK
Once Postfix is running, you should be able to confirm the result with an appropriate telnet com-
mand from a remote system. For example, if Postfix is configured on a system with a 192.168.122.50
IP address, the command would be
# telnet 192.168.122.50 25
The configuration of a smart host in Postfix is based on the relayhost directive. For the parameters
given in the Lab, if the physical host is located on system maui.example.com, the directive in the
main.cf file would be
relayhost = maui.example.com
If Postfix on the server1.example.com system is properly configured as a smart host, e-mails to the
forwarded host should be reliably delivered, and even logged in the appropriate /var/log/maillog file.
Lab 3
With the iptables rule shown in Lab 2, access should already be prohibited from other networks.
However, if you did not include the 192.168.122.0/24 network address in the iptables rule shown
in the answer to Lab 2, a different approach is available. You can use options available in the
/etc/postfix/access file, such as the following to reject messages from the example.org network.
If your example.org network uses a different IP address, revise accordingly.
192.168.100 REJECT
It should be easy to verify connections to the SMTP server from a remote system. From pro-
hibited networks, when you run a command like: telnet 192.168.122.50 25 from a host on the
192.168.100.0/24 network, you should see the following output:
Trying 192.168.122.50...
Self Test 41
Lab 4
This lab should be straightforward. As long as sendmail and sendmail-cf are installed on the local
system, the basic steps to make the move from Postfix to sendmail are as follows:
1. Stop the Postfix service with a command like /etc/init.d/postfix stop.
2. Run the alternatives --config mta script, and select sendmail.
Lab 5
IPv6 networking is not enabled on some systems. But when it is, open the sendmail.mc file in the
/etc/mail directory. To configure sendmail to accept connections from both IPv4 and IPv6 addresses,
first disable the following directive. The added dnl in front turns it into a comment.
dnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl
Next, to let sendmail listen for both IPv4 and IPv6 traffic, activate the following directive:
DAEMON_OPTIONS(`Name=MTA-v4, Family=inet, Name=MTA-v6, Family=inet6')
If successful, you should be able to connect to the system with either of the following commands:
# telnet ::1 25
# telnet 127.0.0.1 25
Forwarding from the root account can be enabled through the /etc/aliases file, as explained in the
answer to Lab 1.
Lab 6
In sendmail, to disable local-only access in the /etc/mail/sendmail.mc file, comment out the following
line. Unlike in most Linux configuration files, the comment code is a dnl at the start of this line:
DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl
The dnl at the end of the line does not affect the command to its left.
Next, you’ll want to enable support through /etc/mail/access. To allow access to the example.com
network as discussed in this book, add the following line to that file:
192.168.122 RELAY
For this lab, assume the sendmail system is on server1.example.com, with IP address
192.168.122.50, and the physical system is on maui.example.com on IP address 192.168.122.1.
Return to the sendmail.mc file, and then look at this directive:
dnl define(`SMART_HOST', `smtp.your.provider')dnl
Lab 7
This lab is quite similar to Lab 2. While there are options in the sendmail configuration files, the
most efficient way to limit access to a specific network is still with an appropriate iptables-based
firewall rule. The rule discussed in the answer to Lab 2 would also work in this case. Alternatively,
you can configure access limits in the /etc/mail/access file, such as
Connect: 192.168.122 OK
Connect: 192.168.100 REJECT