Configuring Virtual Domain Aliases

By Steve Coile <scoile@patriot.net>

Contents

Summary

This procedure will enable Sendmail's virtual user table, which allows you to configure user-specific and domain-wide e-mail aliases for domains other than the host system's actual domain.  This is of particular interest to Internet service providers and other organizations whose mail servers receive and process mail for multiple domains.

Requirements

In order to make use of this feature, you should have Sendmail 8.8.5 or higher installed.  Red Hat Linux 4 systems should be using the sendmail-8.8.5-2 package provided by Red Hat Software (available as an update for 4.1 and 4.0).  You must also have the M4 configuration files installed.  RHL includes these in the sendmail-cf-8.8.5-2 package.

These instructions assume you are using the stock sendmail-8.8.5-2 and sendmail-cf-8.8.5-2 packages provided by Red Hat Software.

Installation

Add the following line to your Sendmail M4 configuration file (the M4 configuration file supplied with the sendmail-cf-8.8.5-2 package is /usr/lib/sendmail-cf/cf/redhat.mc):

FEATURE(virtusertable)

Typically, this line is appropriately placed near the bottom of the M4 configuration file.  If the line already exists in your M4 configuration file, you need make no changes to the file at all.

Next, generate a new Sendmail configuration file by issuing the following commands.  The generated configuration file will be named "redhat.cf" and will be located in the /usr/lib/sendmail-cf/cf directory.

cd /usr/lib/sendmail-cf/cf
m4 redhat.mc > redhat.cf

You may wish to compare the newly-generated configuration file with your active configuration file before replacing the active configuration file.  One way to compare the changes is to use the "diff" command:

diff -U0 /etc/sendmail.cf redhat.cf

Finally, replace the active Sendmail configuration file with the new configuration file and restart Sendmail:

cat redhat.cf > /etc/sendmail.cf
/etc/rc.d/init.d/sendmail.init stop
killall sendmail
/etc/rc.d/init.d/sendmail.init start

Configuration

The virtual user table uses two configuration files.  The first, /etc/virtusertable, is a text file containing the alias definitions.  The second file, /etc/virtusertable.db, is generated by this procedure and is the actual alias database used by Sendmail.

After creating or modifying /etc/virtusertable, you must execute the following command to make Sendmail aware of the new aliases:

makemap hash virtusertable.db < /etc/virtusertable

File Format

The primary configuration file, /etc/virtusertable, is a text file that contains a list of virtual and forwarding address pairs that map virtual addresses to forwarding addresses.  Incoming mail addressed to a virtual address is transparently redirected to the associated forwarding address.

Each data line in the configuration file should be of the following format:

[username]@hostname forward

Where "[username]" represents an optional username portion of the original recipient address, "hostname" represents the host or domain name portion of the original recipient address, and "forward" represents the address to which the mail should be redirected.  If "[username]" is omitted, mail to any address within the given domain will be passed to the forwarding address.

For example, to forward mail addressed to "jqpublic@somewhere.com" to "joeuser@mydomain.net":

jqpublic@somewhere.com joeuser@mydomain.net

To forward all mail addressed to any user in the "somewhere.com" to "jrandom@mydomain.net":

@somewhere.com jrandom@mydomain.net

Specific virtual domain aliases (those including the username portion of the address) have precedence over the general aliases (those including only the host or domain name portion of the address).  Upon receiving an incoming message, Sendmail will first search for the specific recipient, then for the recipient's domain alone.

References

sendmail
Second edition; by Bryan Costales and Eric Allman. O'Reilly & Associates, Inc., publisher.  ISBN 1-56592-222-0.  Page 274.

Sendmail Virtual Hosting Tips
http://www.redhat.com/support/docs/rhl/Sendmail-Virtual-Hosts-Tips

Virtual Hosting with Sendmail
http://www.sendmail.org/virtual-hosting.html