Sendmail as a Gateway to a LAN Mail Server
These are the steps involved in setting up a default installation of Sendmail (8.13.8) in Red Hat Enterprise Linux 5.1 (CentOS 5.1, etc) as a mail gateway from an external (public) address to an internet LAN (Local Area Network) mail server.
Required Packages:
- sendmail
- sendmail-cf
If you need help installing a package, please read how to install packages using YUM.
First off we're going to check that the /etc/hosts file is correct as Sendmail needs to determine the host name by this:
cat /etc/hosts
127.0.0.1 ux-mail.example.com ux-mail
localhost.localdomain localhost
By default Sendmail is listening on the loopback interface, which means it only allows mail to be sent from the server it is running on. Sendmail needs to be configured to listen on the NIC (Network Interface Card) as Sendmail needs to act as a server.
We have to edit /etc/mail/sendmail.mc to make Sendmail listen on the NIC. To make Sendmail skip a certain command, we have to add dnl (delete to new line) to the beginning of the line, since it will then be skipped by the M4 processor. In this case, we want to tell it to skip the command that binds it to the local loopback adapter by changing a line:
Change the line:
DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1,Name=MTA')
To:
dnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1,Name=MTA')
Do the same to the following line to take precautions against spam by not accepting mail from a domain that doesn't exist:
Change the line:
FEATURE(`accept_unresolveble_domains')
To:
dnl FEATURE(`accept_unresolveble_domains')
Also, to forward all *@example.com mail to int-mail.example.com server, add the mailertable feature to the Sendmail configuration file (/etc/mail/sendmail.mc). Add this line towards the bottom, before any MAILER() calls:
FEATURE(`mailertable')
Rebuild the sendmail.cf file and restart Sendmail for the changes to take effect:
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
Edit the /etc/mail/access file and add the following lines to allow relaying messages from an example server (192.168.100.30) and an example domain (example.com), just make sure to change the IP address to your server's address, and the domain to your domain name:
localhost.localdomain RELAY
localhost RELAY
127.0.0.1 RELAY
192.168.100.30 RELAY
example.com RELAY
Then we need to convert the /etc/mail/access file to a Sendmail readable database using makemap:
cd /etc/mail
makemap hash access < access
Next we have to add a line to our mailertable file so sendmail knows where to relay the mail for domain. Edit /etc/mail/mailertable and add:
example.com smtp:[192.168.100.30] # My int-mail.domain.com server
Now we convert the /etc/mail/mailertable file to Sendmail readable database using makemap:
cd /etc/mail
makemap hash mailertable < mailertable
We have to make sure there is no example.com entry in our local host names file by running Sendmail in test mode and showing a list of domains it considers local:
sendmail -bt -C./sendmail.cf
Should return somthing like the following:
ADDRESS TEST MODE (ruleset 3 NOT automatically invoked)
Enter
At the > prompt, enter the command:
> $=w
Which should return something like:
ux-mail.example.com
ux-mail
localhost.localdomain
localhost
[127.0.0.1]
Type /quit at the prompt to exit:
> /quit
Restart Sendmail to activate all the changes we've made:
service sendmail restart
And we're done!