Weldon Whipple <weldon@whipple.org>
Creating or modifying a sendmail.cf file is a daunting task for new sendmail administrators, as well as "returning" sendmail administrators (administrators who worked with sendmail--say--five years ago and have been reassigned to sendmail responsibilities). Hopefully this document will help give you a running start. (At the time of this writing, 8.12.10 is the current version of sendmail.)
This document tells how to modify/create the main sendmail.cf file, not the submit.cf file.
Before you modify your sendmail.cf file, make sure you know which configuration file sendmail is using by issuing the following command (as root):
sendmail -d0.11
(After issuing the command, you will probably need to press Ctrl-c to return to a shell prompt.)
On my server, sendmail uses the sendmail.cf file located at /etc/mail/sendmail.cf.
The mc file used to generate your sendmail.cf might be in one of the following places:
On my main mail server, the mc file is named /etc/mail/mail.whipple.org.mc ...
That isn't a typo! The sendmail distribution (from sendmail.org) assumes that the mc file that will generate your sendmail.cf is in a directory named "cf", which is a subdirectory of another directory named cf!If you have trouble locating the cf/cf directory try the following command (as root):
find / -name cf -type d -print
On my Slackware box, the cf/cf directory is at /home/weldon/src/contrib/sendmail/cf/cf. Just because you found the cf/cf directory doesn't necessarily mean that you have located "your" mc file. The sendmail distribution ships with a number of "sample" mc and cf files in the cf/cf directory, You probably won't want to use one of those sample files as your mc file (but maybe you will ...?).
If you can't find the mc file that generated your sendmail.cf, open an editor and enter the following (for starters):
OSTYPE(linux) MAILER(local) MAILER(smtp)
It is entirely possible that the above will generate a functioning sendmail.cf for your server--especially if you are running a linux server. If your server isn't running linux, you will need to modify the OSTYPE line. To find allowable values, browse the directory cf/ostype (where the cf in cf/ostype is the same as the first cf in cf/cf--the sendmail distribution directory that contains sample mc files). In the cf/ostype directory try to identify a file that matches the name of your OS, then remove the trailing ".m4" and use the name as an argument to the OSTYPE macro.
After editing the file, save it in the cf/cf, /etc/mail, or other directory that contains other mc files.
Because each OS's sendmail configuration conventions might differ slightly, instructions for generating the mc file will vary. Here are a few methods to try:
make <cf-name>.cfwhere <cf-name>.cf is the same as the name of your mc file, substituting "cf" for the trailing "mc".
./Build <cf-name>.cf
sh Build <cf-name>.cf
make <cf-name>.cfwhere <cf-name>.cf is the same as the name of your mc file, substituting "cf" for the trailing "mc".
m4 /usr/share/sendmail/cf/m4 <mc-name> > <cf-name>.cfwhere <mc-name> is the name of your mc file and <cf-name>.cf is the cf file you want to generate. (The solitary > between the mc and cf files is a literal greater-than [redirection] sign.)
Note any messages about syntax or other errors, and correct them before proceeding. If none of the above work, your situation is outside the scope of this document.
Before installing the new cf file, make a backup copy of your current sendmail.cf file by issuing a command something like:
cp sendmail.cf sendmail.cf.bak
Then copy your new cf file to replace the current sendmail.cf:
cp -f <cf-name>.cf sendmail.cf
Most sendmail executables will complain if the sendmail.cf is writable. You can make it read-only with the following command:
chmod 444 sendmail.cf
Chances are that your sendmail is running as a daemon. You will need to tell sendmail to re-read the sendmail.cf in order for your new sendmail.cf file to take effect.
Actually, if you are using sendmail 8.12 or later, there are likely two sendmail daemons--one listening for incoming e-mail, as well as the "new" submission daemon. For this exercise, we will restart only the daemon listening for incoming e-mail--the daemon that uses the sendmail.cf file. Some distributions provide special commands for restarting sendmail. I will leave the discovery of those methods to the reader.
Find the process ID of the sendmail daemon that is listening for incoming e-mail by issuing the command:
ps -auxww | grep 'sendmail.*connections'
Some unixes don't recognize the ps command options shown above. On Solaris, for example, you need to replace "-auxww" with "-ef".
On my Slackware linux box the command output includes the line:
root 3893 0.0 1.6 4064 500 ? S Nov11 7:39 sendmail: accepting connections
In this case, the process ID is 3893.
Depending on how busy your server is, the "accepting" near the end of the line might instead say something like "delaying", "deferring", or "rejecting".
Send sendmail the "hangup" signal (SIGHUP) with by issuing the following command:
kill -HUP <pid>
where <pid> is the sendmail's process ID.
Using the process ID from my Slackware example above, the command would be "kill -HUP 3893".
Send a few e-mails to the server to make sure that it works as well as it did with the previous sendmail.cf file. Check the sendmail log file (probably /var/log/maillog or /var/log/messages) to make sure that sendmail still receives mail. If it doesn't, rename your backup sendmail.cf and restart sendmail.
Although the earlier three-line mc file might possibly meet your needs, it probably doesn't. You might want to include one or more of the following lines as well:
If the answer is "yes," add the use_cw_file feature and create a file named /etc/mail/local-host-names, which lists all the domains that you receive mail for.
Note that the two single quotes that surround the arguments are different: in each line, the first is a "back" quote; the second is an apostrophe.
If my server received local mail for whipple.org and technoids.org, my local-host-names file would look like the following:whipple.org technoids.org
If I want sendmail to receive mail for webmaster@whipple.org and for webmaster@technoids.org, I can create a file named /etc/mail/virtusertable, which contains the lines:webmaster@whipple.org weldon webmaster@technoids.org morrisweldon and morris are local users on this mail server; alternately, they could be aliases in the /etc/mail/aliases file.
Showing all possible formats of lines in the virtusertable are beyond the scope of this document.
After editing the virtusertable, you need to create a database file. One of the following commands should work in most cases (with /etc/mail as the current directory):
makemap hash virtusertable < virtusertable makemap btree virtusertable < virtusertable
Many operating systems or distributions will have easier ways to generate the virtusertable database. On FreeBSD, for example, you can issue this command (while /etc/mail is the current directory):make
To block incoming e-mail from IP address 1.2.3.4, I could add the following line to /etc/mail/access:1.2.3.4 REJECT
After editing the access file, you need to create a database file. One of the following commands should work in most cases (with /etc/mail as the current directory):
makemap hash access < access makemap btree access < access
If you add all of the additional lines described in this section, your mc file will look like this:
OSTYPE(linux) FEATURE(`use_cw_file') FEATURE(`virtusertable') FEATURE(`access_db') MAILER(local) MAILER(smtp)
You can learn more about sendmail configuration in many places. Some of the most useful information sources are:
If you were able to locate the cf/README, you can probably locate doc/op. While in the cf directory (containing the README file), change to the parent directory. Assuming that you see a doc directory, issue the command "cd doc/op".
make op.pdfIf that doesn't work, you can generate an ASCII text file with:
make op.txt
Once you have a viewable copy of the Guide, you will notice that much of the information is given in terms of what appears in the sendmail.cf file (as opposed to the mc file). If you find an answer to a question in the Guide and want to incorporate it in your sendmail.cf file, you will need to consult the cf/README and the Bat book to find what changes to add to your mc file to cause the desired changes to appear in the sendmail.cf file.