Getting Started on Email Services with Linux

Linux.com
volunteer Earl Peters delivers a comprehensive explanation of email
services on Linux in a networked environment. This articles covers
DNS and Sendmail in some detail, including their configuration
files, and rounds out with a close look at setting up clients on
Windows NT Workstation.

Page 1 of 1

Project Purpose and Overview:

I started this project primarily to learn how to use the Linux
operating system in a networked environment. The purpose of this
project was to create an e-mail server on Linux, and to have
workstations retrieve mail from that server. For the email server I
used Slackware Linux 7.1. I used Windows NT Workstation for the
workstations. I only set up two different workstations, but you can
set up others in the same way I have explained below. The server
was given an IP address of 10.5.16.14, while the two workstations
were 10.5.16.12 and 10.5.16.15. The gateway system to the Internet
had an address of 10.5.16.1.

This document will give you an idea of how to set up a DNS and
configure most Windows clients to retrieve mail from a Linux based
email server. I would recommend that you have a moderate skill
level with the Linux operating system; otherwise some sections may
get a little confusing.

Setting Up the DNS Services

First you need a way for your email clients to be able to see
each other and more importantly see the mail server itself. There
are a few methods you can use to do this, such as adding the
correct static IP values to your hosts file in Microsoft Windows
and Linux. I've decided to set up a DNS with Linux.

Before I went all-out with the DNS, I made a resolving, caching
DNS to make sure I could get the DNS to see out to the Internet.
Here's what the following files looked like (the names include the
directory in which they should be located):

/etc/named.conf /*
* A simple BIND 8 configuration
*/

options {
directory "/var/named";
};

zone "." {
type hint;
file "root.hints";
};

zone "0.0.127.in-addr.arpa" {
type master;
file "127.0.0";
};

The directory /var/named line tells named where to
look for the files specified in this configuration file. The zone
"." has two lines. The first line is the type line, which is set to
hint. Hint instructs the DNS, if you can't find the address for
something, look in the file specified. The second is the file line,
which specifies in which file to look. The
root.hints> file contains the names and addresses
of the primary name servers the Internet uses. The zone
0.0.127.in-addr.arpa has similar lines to the zone "."
section, the difference being that it specifies the type as
master, which means our DNS is the master DNS for the
127.0.0 IP numbers.

/var/named/root.hints ;
; There might be opening comments here if you already have this
file.
; If not don't worry.
;
. 6D IN NS M.ROOT-SERVERS.NET.
. 6D IN NS I.ROOT-SERVERS.NET.
. 6D IN NS E.ROOT-SERVERS.NET.
. 6D IN NS D.ROOT-SERVERS.NET.
. 6D IN NS A.ROOT-SERVERS.NET.
. 6D IN NS H.ROOT-SERVERS.NET.
. 6D IN NS C.ROOT-SERVERS.NET.
. 6D IN NS G.ROOT-SERVERS.NET.
. 6D IN NS F.ROOT-SERVERS.NET.
. 6D IN NS B.ROOT-SERVERS.NET.
. 6D IN NS J.ROOT-SERVERS.NET.
. 6D IN NS K.ROOT-SERVERS.NET.
. 6D IN NS L.ROOT-SERVERS.NET.
;
M.ROOT-SERVERS.NET. 6D IN A 202.12.27.33
I.ROOT-SERVERS.NET. 6D IN A 192.36.148.17
E.ROOT-SERVERS.NET. 6D IN A 192.203.230.10
D.ROOT-SERVERS.NET. 6D IN A 128.8.10.90
A.ROOT-SERVERS.NET. 6D IN A 198.41.0.4
H.ROOT-SERVERS.NET. 6D IN A 128.63.2.53
C.ROOT-SERVERS.NET. 6D IN A 192.33.4.12
G.ROOT-SERVERS.NET. 6D IN A 192.112.36.4
F.ROOT-SERVERS.NET. 6D IN A 192.5.5.241
B.ROOT-SERVERS.NET. 6D IN A 128.9.0.107
J.ROOT-SERVERS.NET. 6D IN A 198.41.0.10
K.ROOT-SERVERS.NET. 6D IN A 193.0.14.129
L.ROOT-SERVERS.NET. 6D IN A 198.32.64.12

This is the root.hints file. You can cut and paste
this one if you would like, but the file does need to be updated
every once in while. I will explain updating the file in the
maintenance section at the bottom of this article.

The explanation for this file is a lengthy one, so I'm going to
shorten it and tell you where to get a full explanation. (If you
would like to know more I would recommend that you read the DNS
HOWTO from the Linux Documentation Project.)

The first line has the mail.peters.com. entry. This
specifies what machine this zone comes from. The other part of the
first line, root.mail.peters.com, specifies who to
send all DNS related email to: root@mail.peters.com.
You should have your own email address in here if you are not the
super user. The next few lines explain how many seconds to refresh,
retry, expire, etc. The NS line specifies what machine is the name
server for this zone (the 127.0.0 numbers). The PTR line says that
127.0.0.1 is named localhost. Please note the periods at the end of
the names of the machines; those are absolutely necessary! If they
weren't there, the name would have peters.com added to the end of
it (i.e. mail.peters.com.peters.com.), a mistake that will result
in many different errors.

OK, there are only a few things left. Next we need to open the
/etc/resolv.conf file. Make sure it looks something
like this:

search peters.com
nameserver 127.0.0.1

These entries tell the machine to try to resolve names through
itself. When it comes to setting up the other machines, you will
want to put in the actual IP number of this machine in instead of
the 127.0.0.1. Next, open your rc.inet2 file in the
/etc/rc.d directory, scroll down until you see the
section that is commented that would normally start "named".
Uncomment those lines or add the following:

if [ -x ${NET}/named ]; then
echo -n " named"
${NET}/named
fi

Next, type "named" (without the quotes, of course). Now type in
"tail /var/log/messages", and this will display the last few lines
of the file. It should say something like "hint zone . loaded
successfully", and "master zone "0.0.127.in-addr.arpa" loaded
successfully". Basically, you don't want to see anything that
remotely resembles an error message.

Testing

Now try pinging, lookups, and digging some addresses. I
generally just do it with yahoo.com because I know what addresses I
should get back. This is how the commands would look:

dig www.yahoo.com
nslookup www.yahoo.com
ping -c 10 www.yahoo.com

If it seems things are not working correctly, go and read the
DNS HOWTO. There may have been updates to named since
I've written this.

If this has all worked so far, congratulations! It's now time to
make this a real DNS.

I'm going to try to explain this type of file a little more in
depth. The first PTR line (12 PTR ntclient1.peters.com.) specifies
that ntclient1.peters.com has an IP address of 10.5.16.12. This is
how that address is figured out: the zone (16.5.10.in-addr.apra) +
PTR. So essentially that mean 10.5.16 + 12 = 10.5.16.12. The
address much match the one specified in the peters.com zone
file.

Now that you've added those lines, and created the two files,
you need to restart named. Do this by typing:

ps -aux | grep named

This will give you the process ID of named and the ps -aux
command. Now you can restart the process with the following kill
command:

kill -HUP Process ID of named

Now the full DNS should be up and running: Try doing an nslookup
of mail.peters.com, you should get a response for it, not an
error.

Configuring SENDMAIL

Sendmail is a program automatically installed when you install
Linux onto a hard drive. With Slackware, Linux 7.1 the
configuration files for sendmail is in the /etc/mail/
directory. If you would like to learn more on sendmail, please
visit Sendmail.org. There are only a few files you need to
edit.

I had to add the Cwlocalhost line, the Fw/etc/mail/sendmail.cw
line, and the Djpeters.com line so that sendmail would accept
emails to a person with @peters.com at the end of their address.
The sendmail.cw line is a list of aliases that sendmail will accept
mail to, and send mail from. The file looked like this:

/etc/mail/sendmail.cw mail
mail.peters.com
peters.com.
localhost

With this file being set up the way it is, if someone sends mail
to user@peters.com, the user will get that mail.

I also had to create a file called relay domains. That file is
set up so that sendmail will not deliver mail from unfamiliar
machines or domains, essentially preventing spam. This is how the
file looked:

/etc/mail/relay-domains localhost
127.
peters.com.
10.5.16.14.

There is also a file called aliases in the
/etc/mail directory. This file allows you to set up
aliases for a user, or a group of users. The syntax for the line
is: alias_name: real-user1, real-user2, etc. For example, if you
add the line Office: epeters, mweber, root and you then send mail
to office@peters.com the message will be delivered to
epeters, mweber, and root.

Now that the DNS has been created and sendmail has been
configured you're done with the Linux System. The next step is to
configure the clients.

Configuring NT 4.0 Workstation to Read and Send Mail Through
Linux

First step is to get the machines to use the DNS on the Linux
Machine. If you're doing a fresh installation, then you can just
add the IP address of the Linux Machine under the DNS tab when
you're configuring the NIC (Network Interface Card). When NT is
already installed. Follow these steps:

Hold down the ALT key and double click on Network
Neighborhood.

Make sure the IP address tab is the one selected, and add the
gateway's IP address in the Default Gateway field. In this case,
10.5.16.1.

Click on the Protocols tab.

Select TCP/IP Protocol and click on the Properties button.

Click on the DNS tab.

Make sure the Host Name field has the proper name in it.

Add the domain name in the Domain field. In this case,
peters.com.

In the DNS Service Search Order section click on add.

Enter the IP address of the Linux machine and click on
add.

Click OK to go back to the Network Configuration window, then
click OK on that window to save your changes.

Open up Internet Explorer and try to visit
www.yahoo.com, it should work.

Assuming it's all working so far, next we have to set up the
email program to go and get mail from the Linux email server.

Setting up Windows Messaging

Double Click on the Inbox icon on the desktop or run
c:\Program Files\Windows NT\Windows
Messaging/mlset32.exe.

When asked select yes to install Windows Messaging.

When it is done installing double click on the Inbox icon
again.

When asked to select the information service you will use with
Windows Messaging, select only the Internet mail option. Click
next.

Next you will be asked how you connect to your Internet mail
server, select network and click next.

Now it will ask the name or the IP address of the mail server,
select IP address and enter the IP address of the mail server. In
this case, 10.5.16.14.

When asked the mode for transferring messages, select
automatic.

Next you will be asked for an email address and a full name.
Enter the email address for a user as user@peters.com (i.e.
epeters@peters.com). Then put the users full name in the name
field.

Now you will be asked about the mailbox name, and the password.
Enter the users name in the mailbox field (i.e. epeters), and put
that users password in the password field.

When asked about the personal address book file, and the
personal folder file, use the defaults.

Click on finish.

If all worked correctly you should be in Windows Messaging, with
1 email from Microsoft.

Configuring Microsoft Outlook Express

Once in Outlook Express:

lick on the tools menu, and select accounts.

Click on the mail tab, then click on the add button.

A little sub menu will then pop out of the add button, select
mail.

Enter you full name when the Your Name window opens, then click
next.

Make sure the 'I already have an email address' section is
selected. Then enter the email address you will use on the Linux
email server (i.e. epeters@peters.com).

At the top of the next window, make sure you select POP3 for
your incoming mail server.

In the two address fields below, put in the IP address of the
Linux machine. In this case, 10.5.16.14.

Now the Internet Mail Login Window opens up. Put the user name
in the account name field (i.e. epeters), and put the users
password in the password field. Click on remember password. Make
sure the secure authentication option is not
selected.

Next, click finish and you will be back at the Internet
Accounts window. You may now click close.

The next time Outlook goes to get mail it will get it from the
Linux server.

Maintenance

The only maintenance task you have to perform is updating you
root.hints file (with the exception of adding new
systems if you buy them). If you issue the dig command with no
arguments, you will get a display of your current
root.hints file. If you dig one of the nameservers,
you will get an output that looks a lot like a
root.hints file. So you can update your file by doing
exactly that. This is the command to issue:

dig @e.root-servers.net . ns >
root.hints.new

All you need to do is rename root.hints.new to
root.hints and then restart your DNS server.

Closing Remarks

You may have found this tutorial is a little confusing. If so,
the best suggestion I can give you is to read this a few times,
then try implementing it. Developing this tutorial and learning
Linux took me three months, and I know there is much more to be
learned. This tutorial only scratches the surface of email, you can
make an entire career out configuring email servers. If this is
something you are serious about, I would definitely suggest
learning as much as you can on it before thinking about
starting.

Page 1 of 1

Originally published on Linux.com. Released under the Open Content License unless otherwise stated.
Notify Gareth Watts of any
errors or copyright violations.