T-110.5102 Laboratory Works in Networking and Security (5-10 cr)

Lab A2: E-mail server



Description of Exercise

In this exercise you will setup an email server with a filter (spamassassin).

Work Tasks

1. Preparation

In this assignment, you need two hosts (lab1 and lab2). Configure the network between the hosts and add the IPv4 addresses and aliases on both computers to the /etc/hosts file. Stop any daemons that might be listening on the default smtp port.

man hosts (5), netstat (8)

Note: You can use other interfaces than eth0 (e.g., eth1) in this assignment. Remember not to touch the eth0 interface settings in any way, there is a great risk of making your VM unaccessible for yourself.

2. Installing software

On lab1, verify that the following packages are installed (dpkg -l):

postfix,procmail, spamassassin, and mailx.

On lab2, remove packages of postfix, sendmail and then install exim4.

3. Configuring and testing postfix

Edit postfix main configuration file (main.cf, postconf (5)) on lab1. You have to change, at least, the following fields:

  • myhostname (from /etc/hosts)
  • mydestination
  • mynetworks (localhost and virtual machines IP block)

Disable ETRN and VRFY commands. Remember to reload postfix configuration (/etc/init.d/postfix).

Configure exim4 on lab2 to handle local emails and send all the rest to lab1. You might want to use standard debian package configuration tools.

Send a message from lab2 to labrat@lab1 using mail (1). Read the message on lab1 (with mail (1)). See also email message headers. See incoming message information from/var/log/mail.log using tail (1). 

3.1 Explain shortly the incoming mail log messages 2 p
3.2 Explain shortly the email headers. At what point is each header added? 2 p
3.3
What is purpose of the main.cf setting "mydestination"?
1 p
3.4 What is the idea behind the ETRN and VRFY verbs? 2 p 
3.5 Why it is really bad idea to set mynetworks broader than necessary (e.g. to 0.0.0.0/0)?
1 p

4. Configuring procmail and spamassassin

Edit (create if necessary) /etc/procmailrc (5) and add the following lines:

:0fw
| /usr/bin/spamassassin

In main.cf, you have to enable procmail with line

/usr/bin/procmail -a "$USER"

to appropriate field (hint: mailbox_command). Remember to reload postfix configuration. You may need to start the SpamAssassin daemon after flipping the enabling bit in the configuration file (hint: try starting the daemon).

Send an email message from lab2 to labrat@lab1. Read the message on lab1. See email headers. If you do not see spamassassin headers there is something wrong, go back to previous step and see /var/log/maillog.

Use procmail to automatically filter spam messages to a different folder.

Add also a filter for user labrat to automatically save a copy of a message with header [T-110.5102] in the subject field to a different folder. Also forward a copy of the message with the same header to testuser1@lab1 (create user if necessary).

Note: Use .procmailrc file in user's home directory for user-specific rules.  

4.1
How you can automatically filter spam messages to different folder using procmail? Demonstrate by sending a message that gets flagged as spam.
2 p
4.2 Demonstrate the filter rules created for messages with [T-110.5102] in the subject field by sending a message from lab2 to labrat@lab1 using the header. 2 p 
4.3 Explain briefly the additional email headers (compared to step 3.2). 1 p

Final questions

Show only changed fields from main.cf.

5.1
What information is stored in MX records in the DNS system? 1 p
5.2
Explain briefly two ways to make redundant email servers using multiple servers and dns. (hint: see MX records for hut.fi, smtp.hut.fi and tml.hut.fi) 2 p