Библиотека сайта или "Мой Linux Documentation Project"
Linux System Administrator's Survival Guide lsg35.htm
- Configuring sendmail
- Using sendmail Version 8
The most commonly used e-mail program is sendmail, which is supplied with most Linux versions. The sendmail system is extremely powerful and flexible, but it can at times be annoying and difficult to configure and administer because of these very attributes. Setting up sendmail and managing its use for most common e-mail tasks,however, is quite easy, as this chapter will show you. If you are planning to to use sendmail as your mail system, you will find that this chapter provides enough information for all but the most complex networked system.
Before getting started, note that this chapter shows you how to set up more than sendmail. Because sendmail is complex (the best reference manual to the mailer approaches 800 pages), it is often teamed with a utility called IDA, for a combined product often known as sendmail+IDA. IDA makes sendmail much easier to use and is the most common method of using sendmail with Linux. Indeed, with IDA in tow, sendmail becomes the easiest mail transport package available for Linux.
If your system offers only a sendmail version prior to release 8, consider getting sendmail+IDA from an FTP or BBS site. The convenience sendmail+IDA offers far outweighs any hassles in obtaining the files. Some current Linux releases are offering sendmail version 8, which is usually not supplied with IDA. Version 8 of sendmail is considerably easier to set up than previous versions, and because this version is now supplied with most Slackware Linux CD-ROMs (including the one supplied with this book), this chapter also covers sendmail version 8 (without IDA). Check the FTP or BBS sites for more information about sendmail+IDA for this (and later) releases.
The sendmail system by itself (without IDA) is configured primarily though a file usually stored as /etc/sendmail.cf (although some systems place the file in /usr/lib/sendmail.cf or other locations). The language used in the sendmail.cf file is completely different than other configuration files and is very complex. To see for yourself, examine the sendmail.cf file and try to make sense of it.
The sendmail.cf file handles the default actions of the sendmail system. Several other files are involved in the configuration, too:
|decnetxtable||Converts generic addresses to DECnet addresses|
|genericfrom||Converts internal addresses into generic ones|
|mailertable||Defines any special treatment for remote hosts and domains|
|pathtable||Defines the UUCP paths to remote machines and domains|
|uucpxtable||Forces the delivery of UUCP mail from DNS addresses|
|uucprelays||Allows shortcuts to remote hosts|
|xaliases||Converts generic addresses to internal ones|
These tables are detailed later in this chapter. As mentioned, all the sendmail configuration files are difficult to edit manually. Using sendmail+IDA makes configuration much easier, as IDA handles configuration through table-driven options. Each table has a much simpler syntax than the sendmail.cf file.
The sendmail+IDA system uses a preprocessor such as m4 or dbm to generate the proper configuration files after you have specified values for many parameters. After using the preprocessor, the system uses a Makefile to create the final configuration files.
The sendmail.cf File
When you use sendmail+IDA, the sendmail.cf file is not edited directly. Instead, a configuration process generates the changes. The configuration routine is driven by a file called sendmail.m4, which provides basic information about your system's name, the pathnames used on your system, and the default mailer used. Although the sendmail.m4 file can get pretty long, it needs only basic information for most Linux installations that use UUCP or SMTP for mail transfers.
<NOTE>Many system administrators like to rename sendmail.m4 to match their system name (such as tpci.m4) in order to prevent the file from being overwritten by accident and to make it obvious which machine the file refers to. If you choose to rename your file, alter all references to sendmail.m4 in this chapter to reflect your new filename.<NOTE>
One of the most important sections of the sendmail.m4 file is the area that defines directories. This area usually starts with a line defining LIBDIR:
dnl #define(LIBDIR, /usr/local/lib/mail)
The LIBDIR directory is where sendmail+IDA looks for configuration files and routing tables. Usually this line is left alone, as the default path is the general location for all Linux mail systems. If the path shown in the sendmail.m4 file is correct, don't modify the file. This path is usually hardcoded into the sendmail binary, and doesn't need to be overwritten by the sendmail.m4 file (or its generated sendmail.cf file). If you need to change this path, you have to remove the dnl from the beginning of the line (which essentially makes the line a comment), add the correct path, and then rebuild sendmail.cf.
The local mailer used by sendmail is defined in the line that contains the variable LOCAL_MAILER_DEF:
This line is necessary because sendmail doesn't handle mail delivery. Another program takes care of this step instead. By default, the value used for the local mailer (which is almost always deliver) is contained in a file called mailers.linux. This file is referenced in the LOCAL_MAILER_DEF entry in the sendmail.m4 file, which means you need to check the mailers.linux file in the same subdirectory (usually /usr/local/lib/mail/mailers.linux) to ensure the deliver program (or whatever delivery agent you use) is properly entered. A typical mailers.linux file looks like the following:
# mailers.linux Mlocal, P=/usr/bin/deliver, F=SlsmFDMP, S=10, R=25/10, A=deliver $u Mprog, P=/bin/sh, F=lsDFMeuP, S=10, A=sh -c $u
The deliver mail delivery agent is also specified in the file Sendmail.mc, which is used to build sendmail.cf. If the name of your delivery agent is not deliver, check the Sendmail.mc file to make sure your mail delivery agent is properly specified. (If you are using deliver, don't worry about this file.) The Sendmail.mc file is important and must be read in when sendmail.m4 is processed. There is usually a line in sendmail.m4 that makes sure this action occurs. The line, which usually occurs at the top of the sendmail.m4 file, looks like the following:
You may need to specify some entries in the PSEUDODOMAINS variable. This variable is used to handle systems that can't expand into domain names properly, usually UUCP networks. The entries in the PSEUDODOMAINS field tells sendmail+IDA not to use DNS for these networks (which would always fail). Typically, the PSEUDODOMAINS variable is set to the following values:
define(PSEUDODOMAINS, BITNET UUCP)dnl
You can use the PSEUDONYMS variable to hide your machine names from the outside world. For example, a mail recipient on another network sees only the address tpci.com regardless of whether mail was sent from merlin.tpci.com or chatton.tpci.com. When you use the PSEUDONYMS variable, sendmail accepts mail from all machines identified in the PSEUDONYMS field. The PSEUDONYMS field is usually used as shown in the following line:
This entry lets any machine with the network type tpci.com send mail through sendmail.
To define the name of your local machine, you use the DEFAULT_HOST variable. This variable is usually defined as the same name as your mail server (or your basic machine's name if you are not on a network). For example, you can use the following entry to set the default mail server's name:
If you do not set a valid name for the DEFAULT_HOST variable, no mail will be returned properly to your system.
If your system is not a mail gateway to the Internet (or other networks that are accessible from your LAN), you can set your Linux system to send mail on to another machine for processing by setting the RELAY_HOST and RELAY_MAILER variables in sendmail.c4. These variables set the name of the mail server that all mail should be passed on to. For example, to set your local system to route all outbound mail to a machine called wizard, you set the following two lines as shown:
define(RELAY_HOST, wizard)dnl define(RELAY_MAILER, UUCP=A)dnl
If you are working with a UUCP-based mail system, you should modify a few more entries in the sendmail.m4 file. These modifications are necessary because a UUCP mail system is often addressed differently than a DNS-based system. The UUCP-specific entries in the sendmail.m4 file usually look like the following:
define(UUCPNAME, tpci)dnl define(UUCPNODES, |uuname|sort|uniq)dnl define(BANGIMPLIESUUCP)dnl define(BANGONLYUUCP)dnl
The first line defining UUCPNAMES specifies the name of the local system in UUCP terms. This name can be different than the name used in DNS, although usually these names will be similar. The UUCPNODES variable defines the commands that are used to produce a list of hostnames for systems you connect to via UUCP.
The BANGIMPLIESUUCP variable tells sendmail to assume that any address containing an exclamation mark (called a bang) is UUCP style. The BANGONLYUUCP variable does the same thing. Both variables are usually set to on (not commented out) because few DNS users use the bang addressing method.
Configuration Table Locations
Several lines in the sendmail.m4 file define configuration tables. For the most part, these configuration tables are under the directory defined by LIBDIR. This section of the sendmail.m4 file has several lines that look like the following:
define(ALIASES, LIBDIR/aliases)dnl define(DOMAINTABLE, LIBDIR/domaintable)dnl
There are about seven configuration file definitions in total. You can change any of these values if you want, but be sure to move the files themselves to the specified location. On the whole, it is best to leave the files in their default locations.
The file decnetxtable is used to translate domain names into DECnet style names. This file is a holdover from earlier versions of sendmail and will probably never be necessary for Linux users (unless your Linux machine is on a DECnet system).
The domaintable file forces sendmail to perform specific instructions after using DNS. The file, which is almost never used on Linux systems, allows you to provide expansion of short-form names. Suppose you often send mail to the host reallylongname.reallybignet.com, but you don't want to type that entry each time. You could place the following entry in the domaintable file
so that whenever you send mail to email@example.com sendmail expands the address to firstname.lastname@example.org. You also can use the domaintable file to correct common typographic mistakes. For example, if many users accidently send mail to abcdef.com instead of abcdfe.com, you could add a line to the domaintable file that corrects the domain name:
The genericfrom table hides local usernames and machine addresses by converting local usernames to a generic ID that has no obvious connection to the username. Linux systems seldom use this table because the general convention is to use real names on e-mail and similar data. The companion file, xaliases, performs the generic to real conversion when mail comes back from the outside world.
The mailertable table defines any special handling for hosts or domains. Most often, mailertable specifies how certain domains or hosts are accessed and which protocol to use for these domains and hosts. You don't have to modify this file if your system only uses UUCP, but you should verify its contents if you use SMTP or DNS.
The mailertable file is read from the first line down, and sendmail processes mail based on each line in the file. For this reason, place the most specific rules at the top of the file, followed by more general rules. Rules give the method of connection first and then list the remote system or domain:
mailer delimiter relayname remote
In this syntax, mailer is the transport to use, delimiter is a special character, relayname is the name of the system to pass the mail to, and remote is the remote host or domain name. The mailer can be one of the following values:
|TCP-A||TCP with Internet-style addresses|
|TCP-U||TCP with UUCP-style addresses|
|UUCP-A||UUCP with Internet-style addresses|
The delimiter has a special meaning and must be one of the following characters:
|!||Strips the hostname from the address before forwarding|
|,||Doesn't modify the address at all|
|:||Removes the hostname only if intermediate hosts are specified|
You can build the mailertable rules quite easily when you are forwarding mail to a remote mail server. For example, to force sendmail to use UUCP through a remote mail server called wizard to connect to the remote system roy.sailing.org, add a rule like the following to the mailertable file:
On a more general level, a rule like this one
The pathtable table defines explicit routing to remote hosts and networks. The format of each line in the pathtable file uses a syntax similar to a UUCP path alias, with entries appearing alphabetically in the file. The pathtable file is rarely used because most Linux systems can handle the routing without explicit instructions.
The uucprelays file short-circuits the UUCP path to a remote site when a better path exists. For example, if your users often use the path wizard!bignet!merlin!tpci and you create a direct link to tpci, you could use the uucprelays file to redirect the mail.
The uucpxtable file is used when a UUCP style address has to be used for mail delivery. The file provides the instructions for converting a DNS format address to a UUCP format address. If you are using a mail server other than your current machine or want to use UUCP to connect to specific machines because of reliability factors, this table is necessary.
This file contains entries that lists the UUCP style name followed by the domain name, as follows:
This entry tells sendmail that any mail for chatton.com should be rerouted via UUCP to chatton (UUCP style addressing). This entry forces mail addresses to email@example.com to be rewritten as chatton!yvonne, an address that UUCP can handle.
Building sendmail.cf from sendmail.m4
Now that you have configured the sendmail.m4 file and its dependent files, you can use the m4 processor to generate the sendmail.cf file. When the sendmail.m4 file is ready to be processed, issue the command
or substitute your site name if you renamed your sendmail.m4 file to reflect your site name. (In other words, if you created a file called tpci.m4, specify tpci.cf in the command).
Once the file has been processed, copy it to the /etc directory (which is where the file normally resides) and start up sendmail with the command
/usr/lib/sendmail -bd -q1h
Using sendmail Version 8
The latest version of sendmail supplied for most Linux systems is version 8. If you didn't see versions 6 or 7, don't worry; they didn't exist. The sendmail system jumped from release 5.X to 8. As of the date of publication, sendmail8+IDA wasn't in general distribution, but it should be available by the time you read this. There are several releases of sendmail version 8, just to make life more complicated. They are all pretty much the same as far as installation and configuration are concerned.
Most Linux CD-ROMs have the source code for sendmail version 8 already compiled into a binary. If you do not have the binary, change to the source directory and use the make command. The Slackware CD-ROM includes the precompiled binaries.
<NOTE>Each release of sendmail version 8 has an installation guide included. On the Slackware CD-ROM release accompanying this book, the installation guide is in the directory /usr/doc/sendmail/op as the file op.me. To format and display this file properly on the screen, use the following command:<NOTE>
nroff -me op.me | more
<NOTE>If you want to send the output to the printer instead, replace the more command with lp, or save the output to a file and print that file directly.<NOTE>
For the most part, sendmail version 8 is similar in configuration details to the other releases of sendmail. One change is the inclusion of four different UUCP mail routines. Choose one of the four UUCP versions based on the following features:
- uucp-old (same as uucp) is classic UUCP that uses a bang-style address and can send to only one address at a time (duplicate messages are sent when multiple recipients are specified). Use this version only if you need compatibility with old-style UUCP systems.
- uucp-new (previously known as suucp) is the same as UUCP except it provides the rmail command to allow several recipients. This version is not much of an improvement over uucp-old.
- uucp-dom allows domain name-style addressing. This version may not be compatible with some systems you have to connect to.
- uucp-uudom is a combination of uucp-new and uucp-dom to provide the best features of both. It allows bang- and DNS-style addresses with proper handling of headers.
As mentioned earlier in this chapter, the sendmail configuration files are daunting to say the least. To make matters easier for administrators, a number of templates are supplied with version 8 that cover most of the common installation configurations. You have to copy one of these templates over the sendmail configuration file and change a few parameters relating to your specific system, but you can leave the majority of the file. Using these templates greatly shortens and simplifies the installation process. (If none of these templates suits your installation, you must manually adjust the configuration file. This process is beyond the scope of this book, so check the supplied documentation for more information.)
The sendmail system uses a number of directories to hold the files it needs, including the configuration file templates. Most of these files are processed by the macro language processor m4. The directories and their contents are as follows:
|cf||This directory provides descriptions of hosts used by sendmail. The raw data files end in .mc (for master configuration) and are used as input; the output produces a file ending with .cf.|
|hack||This directory is a list of hacks used by the m4 macros to provide fixes or extra specifications. These should be avoided as much as possible. The information they supply is properly provided in the main configuration files.|
|m4||This directory contains files with information applicable to all configuration files (site-independent information).|
|mailer||This directory contains files defining the mailers that are used by m4. The files generally provide information for local, UUCP, USENET, fax software, and similar types of mailers.|
|ostype||This directory contains files describing the operating system and its environment.|
|sh||This directory contains shell files used by m4.|
|siteconfig||This directory contains local site information.|
A number of files are important to the sendmail installation and configuration process. These files, their ownership and permission settings (where appropriate), and their purposes are as follows:
- The /usr/sbin/sendmail file is the sendmail binary (the location can change, for example to /usr/lib/sendmail, depending on your installation setup). The file should be owned by root and have permissions set to 553.
- The /etc/sendmail.cf file is the configuration file used by sendmail. This file is sometimes installed as /usr/lib/sendmail.cf.
- The /usr/bin/newaliases file is a symbolic link to the sendmail binary. Create it with the command ln -s /usr/sbin/sendmail /usr/bin/newaliases if the link isn't already installed.
- The /var/spool/mqueue directory is used to hold the mail queue. Create this directory with root as the owner and permissions set to 700. Some installations may prefer the directory /usr/spool/mqueue.
- The /etc/aliases file contains system aliases. This file should include the aliases provided in the lib/aliases file under the sendmail distribution directory.
In order to start sendmail automatically when your Linux system boots, modify the /etc/rc files to include these lines (if they don't already exist):
if [ -f /usr/sbin/sendmail -a -f /etc/sendmail.cf ]; then (cd /var/spool/mqueue; rm -f [lnx]f*) /usr/sbin/sendmail -bd -q30m & echo -n ' sendmail' >/dev/console fi
Using the sendmail Templates
The Slackware Linux distribution that accompanies this book, and most other releases of Linux that provide sendmail version 8, have a few templates provided that set most of the needed parameters. The templates on the Linux CD-ROM accompanying this book are as follows:
- The cf/linux.smtp.mc template is for systems directly connected to the Internet (the default configuration).
- The cf/linux.nodns-smtp.mc template is similar to the above configuration but it's for systems with no nameserver (such as most small LANs).
- The cf/linux.uucp.mc template is for for UUCP-based connections.
If you choose to use one of the template files, examine it carefully to make sure the directories and system names are correct for your system. Make any changes directly into the file. To install one of these configuration files (or any other that you may find that suits your needs), issue the command
m4 config_file.mc > /etc/sendmail.cf
This chapter examined the configuration process for sendmail+IDA, the most common form of sendmail used with Linux. If you plan on using smail instead, read Chapter 36.
Только зарегистрированные пользователи могут оценивать и комментировать статьи.