Find out how to configure Sendmail to work on a single machine responsible for more than one domain.
The popularity of domain hosting has increased exponentially in the last few years for companies of all sizes. All these domains need to be hosted somewhere, but corporate-level hosting of Web sites and mail domains can be expensive. One of the best solutions is virtual hosting, which allows multiple domains to be housed on a single server or server cluster. This is a valuable strategy for both a large company with the hardware and bandwidth to host hundreds of domains and a small business with a mere two domains to control. In this article, we’ll take a look at how to configure Sendmail to work on a single machine responsible for more than one domain.Setting up DNS
When configuring your server to support multiple domains, make sure that you have DNS configured correctly. We won't delve too deeply into DNS since it is outside of the scope of this article, but you should know that your DNS server must have an MX record for each domain for which you are hosting mail. The entry will look something like this:domain1.com.IN MX 10 mail.domain1.com.
This will, of course, need to be done with each domain that your server will be receiving mail for. The entry for mail should also be an A (host) record as opposed to a CNAME (alias) and should point to the IP address of your server.Configuring Sendmail
Since version 8.10, Sendmail has made significant improvements in supporting multiple domains. It is a great deal easier to configure and no longer requires any sort of hack to make it work. The first step is to make sure that the following feature is included in yoursendmail.mc
file prior to installing Sendmail:FEATURE(`virtusertable', `dbm /etc/mail/virtusertable')dnl
This lets Sendmail know that you will be creating a virtual user table to allow support for multiple domains. This is really the key to virtual hosting with Sendmail. Also, if you're using NEWDB in place of NDBM, you need to replacedbm
in the above line.
Once that is set up and Sendmail is installed, you can work with virtual hosting by using the file/etc/mail/virtusertable
, which will look something like this:firstname.lastname@example.org@email@example.com@domain1.com root
The first argument above is the intended recipient as received by Sendmail, and the second argument is the target is for local delivery (or for forwarding to another Internet e-mail address). On mail servers that host mail for many domains, it might be a good idea to create a separate file for each domain and concatenate them with a simple script.
After creating the necessary/etc/mail/virtusertable
, there's one more step: A database must be created. Sendmail will not load the plain text file in this case but will look forvirtusertable.db
. You can create this file with the following command (run as root):makemap dbm /etc/mail/virtusertable < /etc/mail/virtusertable
Remember that although you may have the same e-mail address used for more than one domain (e.g., firstname.lastname@example.org and email@example.com), each one needs to point to a separate local user. Keeping this in mind will help avoid later problems like one user receiving another’s mail.
When you're hosting multiple domains, you need to include another important configuration option in yoursendmail.mc
file prior to installing Sendmail:FEATURE(use_CW_FILE)
This lets Sendmail know that you will provide it with a list of domains for which it may accept mail. On most recent installations, this will be/etc/mail/local-host-names
. This is a plain text file with a domain on each line, which will look something like this:# /etc/mail/local-host-names# aliases for the local hostdomain1.commail.domain1.comdomain2.commail.domain2.com
Without an entry for all the domains your server will be serving mail for, Sendmail will reject delivery. But if you make sure that this file and the virtual user database are configured, you shouldn’t run into any problems.Reverse mapping
Reverse mapping allows users to send mail from your server and have the correct domain name appended to the outbound e-mail. This feature works almost exactly as thevirtusertable
, but in reverse. It is done with a “generics table” and requires the following lines be added tosendmail.mc
:FEATURE(`genericstable', `dbm /etc/mail/genericstable')dnlGENERICS_DOMAIN_FILE(`/etc/mail/generics-domains')dnl
In addition, you will need to create/etc/mail/genericstable
, which is just like/etc/mail/virtusertable
except that the columns need to be switched so that column one shows the local user name and column two shows the e-mail username and domain name you want that user’s outgoing mail to have. For example:tom firstname.lastname@example.org harry email@example.com@domain2.com
Restart Sendmail, and it should allow you to perform as a virtual mail host for multiple domains. You can usually restart Sendmail by passing it akill –1 [PID of Sendmail]
or running/etc/init.d/sendmail restart
Hosting multiple domains has never been easier with Sendmail 8.10 and later, thanks to the built-in virtual hosting support. With the addition of a couple of configuration files, you can be up and running in a short period of time. Virtual hosting allows you to act as a mail server for multiple domains housed on the same server. Not only will this save you money in hardware, it will cut down on the space your server farm requires.Have a comment or a question?We look forward to getting your input and hearing about your experiences regarding this topic. Post a comment or a question about this article.