Protecting your email server with Alpine

From Alpine Linux
Revision as of 12:16, 6 June 2008 by Clandmeter (talk | contribs)
Jump to: navigation, search


This document will outline how you can setup a spam/virus gateway with Alpine Linux. I want to say first that this is not the only way of setting up such a system. There are many ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you!

First thing I want to mention is, it is probably not a good way to setup Postfix on a disk less system (having the mailer spool in memory). If you would ever suffer from power failure you would loose the contents of your Postfix spool. That said, in our organization we are using a UPS device to supply our servers with backup power, so the chances that our server would shutdown because of power failure is minimal (and we are prepared to take this risk).

For this particular setup we are going to use the following:

  • Mailer daemon: Postfix
  • Virus scanner: Clamav
  • SMTP filter: Clamsmtp
  • Greylisting server: Gross
  • Extra definitions: SaneSecurity & MSRBL
  • Exchange 2003 users/groups in relay_recipient_maps
  • Alpine Linux 1.7.19 (some packages are not available before this version)

Setting up Postfix

The first thing we are going to install is our mailer daemon:

apkl_add postfix

This will install Postfix with a default configuration in /etc/postfix. Lets first take a look at, this is the (as the name implies) main configuration file for Postfix. I will show you my configuration file which you can use (I've commented out some options which we enable later on):

mynetworks = lan-net/24,
transport_maps = hash:/etc/postfix/transport
relay_domains = $transport_maps
smtpd_helo_required = yes
disable_vrfy_command = yes
#relay_recipient_maps = hash:/etc/postfix/exchange_receipients
smtpd_recipient_restrictions =
    #check_policy_service inet:,
smtpd_data_restrictions =
#content_filter = scan:[]:10025

These are the minimal settings I use to setup a postfix mail gateway. If you are looking for other settings please issue the following command:

postconf |more

This will display your current default configuration. If you want to change any of these settings you can add them to and reload postfix.

Looking at my file you will see the setting "transport_maps". This setting refers to a file inside the postfix config directory which will hold information for postfix to which server it should forward email to. It should look similar like this:

domain-a.tld   smtp:[]
domain-b.tld   smtp:[]

When ever an email enters our mail gateway for a domain specified in our "transport_maps" file it will forward this email after processing to the IP address assigned. For complete documentation please refer to the postfix docs. When are ready editing this file, issue the following command:

postmap /etc/postfix/transport

This will create a hash db of this file which will be easier/faster for postfix to read.

The second setting we will look at is 'relay_domains". This setting will tell postfix for which domains it will relay emails. Because this setting will most probably be the same as the domains we mention in "transport_maps" we can just link to it.

Now your basic email gateway is ready and you can start it but remember there will be no virus or spam filtering.

/etc/init.d/postfix start

We can add it to init.d:

rc_add -k postfix