How to install Postfix, Amavisd-new, SpamAssassin, Pyzor, Razor, DCC, and ClamAV on Fedora Core 4 - v2.1.8

By RoNNY Nussbaum

 

 

Greetings!

 

This document describes how to install Postfix, Amavisd-new, SpamAssassin, Pyzor, Razor, and DCC on one box running Fedora Core 4. The installation assumes that Postfix will not be the final destination of incoming mail. Also, no e-mail is sent through it to the outside world. It is a simple MTA that receives e-mail, scans it, and moves it to another MTA for processing.

 

For those of you still working on a v2.1.7 setup, the older document is here.

 

You need to know some Linux to use this guide. At the minimum you need to know how to work with vi (see Appendix B). Also, I’m not a Linux expert, so some of you gurus out there may find some better ways to do things. That’s fine. Feel free to give me feedback. It’s important to keep this document updated, your input is invaluable, and will help make this document better. For all questions or comments, please e-mail me at ronnynussbaum [at] gmail [dot] com.

 

Use this document at your own risk. I take absolutely no responsibility for any losses or damages incurred as a result of using this installation, but it does work…really!

 

This document was inspired by the original document written by Scott L. Henderson, however, it’s a document that I wrote on my own, and has some more settings, tweaks, and tricks that I learned about from my own experience, and from the good people in the mailing lists. I tried to be very clear, and explain each setting. If you find something to be confusing, please let me know.

 

I’d like to also mention the great document by mr88talent. His document describes a similar installation, but on a Debian rather than Fedora. You can find his document here: http://www200.pair.com/mecham/spam/, and I have found it to contain some valuable resources that are good for Fedora as well, and were used in this document.

 

I will start by installing Postfix, which will be our mail server in this case. Postfix uses amavisd-new to communicate with content filters, such as SpamAssassin, and ClamAV. SpamAssassin is using its own anti-spam techniques, as well as communicating with third-party services, such as Razor, Pyzor, and DCC, to detect if a message is spam or not. In this document, I will refer to amavis-new as Amavisd, and sometimes amavisd. In any case, I’m talking about amavisd-new, which can be found here: http://www.ijs.si/software/amavisd/.

 

You will also see situation where I claim that something will happen if we set a specific variable to a specific value.

Please keep in mind that this doesn’t necessarily means that in all cases, and all configurations, you will get the same results.

The setting may be true for this configuration only.

 

This document works best if you view it at a resolution of 1024x768. If you have a lower resolution browser window, make sure to pay careful attention to the commands that you type. Spaces tend to disappear when your browser wraps the lines. Also, some people reported printing the document, and that some underscores disappeared in the process. Please double-check every command that you type against the web version of the document.

 

One final note: this installation is for Fedora Core 4, but this document started its life as the installation manual for Fedora Core 3. With proper adjustment, it can be easily used on FC3. In fact, I think that the only thing that’s a little different is the installation part. If you chose to install FC3 instead of FC4, I suggest that you’ll simply ignore the differences that you see during install. It should work fine.

 

Another final note: please please please check the forum. There’s answers to a lot of your questions there.

 

Enjoy building the server.

 

-RoNNY

 

Table of Contents

How to install Postfix, Amavisd-new, SpamAssassin, Pyzor, Razor, DCC, and ClamAV on Fedora Core 4 - v2.1.6  1

Table of Contents. 2

Conventions Used In This Manual 4

Installing Fedora Core 4. 6

Errors During Boot 8

After the Initial Reboot 8

Login to the System for the First Time. 8

Firewall Protection. 9

PuTTY.. 9

WinSCP. 9

Disabling Some Unneeded Daemons (Services) 10

Updating the System.. 10

Changing the Language Preferences. 11

Make vi Show Files in Color (use vim) 11

Optional: Configuring ls. 11

Downloading the Required Software. 12

Set the System to Boot into Text Mode. 12

Creating Some Required Users. 12

Installing Postfix. 13

Configuring Postfix. 14

A Word About DNS and MX Records. 14

The master.cf File. 16

The main.cf File. 16

Postfix’s Own Anti-Spam Filters. 19

The virtual File. 22

The transport File. 23

The client_access File. 23

The helo_access File. 24

The sender_access File. 25

The recipient_access File. 25

Asynchronous Logging. 26

Testing Postfix. 26

Searching the Log. 27

Testing Incoming Mail 28

Setting Postfix to Start Automatically at System Boot 29

Saving Postfix’s Configuration. 29

Address Verification. 30

Installing SpamAssassin. 31

The Trusted Path Problem.. 33

Installing Amavisd-New.. 34

An Overview of Amavis’ Quarantine, Notifications, and Actions. 34

Configuring Amavisd-New.. 37

A Few Words About Tags. 37

Creating Some Directories for Amavisd. 42

Installing Some Prerequisites for Amavisd. 42

About Sender Policy Framework (SPF) 43

Creating White-List and Black-List files. 44

Testing Amavisd. 44

Setting Postfix to Use Amavisd. 45

Setting Amavisd to Start Automatically at System Boot 46

Amavis’ Little Children. 46

Installing Razor 47

Configuring Razor 48

Installing Pyzor 49

Installing DCC.. 50

More SpamAssassin Configuration. 52

Testing the Server 54

Reminder Regarding Configuration Changes. 56

Installing ClamAV.. 57

Configuring ClamAV.. 58

Testing ClamAV.. 59

Issuing Commands to clamd. 60

Alternative clamd Configuration. 61

Setting ClamAV (clamd) to Start Automatically at System Boot 62

Setting ClamAV to Auto-Update hourly. 63

Logwatch. 63

Logrotate. 64

Backing-up the Server’s Configuration. 64

Working with sa-learn. 67

Tweaking SpamAssassin’s Tests Scores. 68

Generating Mail Reports. 69

Appendix A: Setting up the IP address manually. 70

Setting up DNS resolution. 71

Modifying the hosts file. 71

Changing the host name. 71

Setting Up Multiple IPs for the Server 71

Appendix B: Very short vi manual 73

Appendix C: Postfix startup script 73

Appendix D: mime_mail script 75

Appendix E: Upgrading the Server’s Software. 80

Postfix. 80

SpamAssassin. 81

Amavis. 81

Razor 81

Pyzor 81

DCC.. 82

ClamAV.. 82

Revisions to this Document 84

To Do: 85

Thanks. 85

 

Conventions Used In This Manual

Throughout the manual, commands that should be typed in by you in the shell prompt, or in vi, will look like this. Several commands that need to be typed one after the other, are separated from each other with a white line:
command 1
command 2

When a command is too long to fit in one line its second, third, fourth, etc, lines will be indented:

this command is so long, so I had to type it in several lines

 and then indent it

 over and over again!

Note that the above conventions also may be used even when you type something in vi, and not necessarily the shell prompt.

 

Please read the very short vi manual in Appendix B. From now on, I will assume that you know how to use vi, so that when I write “edit the file”, “or “save close the file”; you’ll know what I mean. Also, unless otherwise stated, each command should be issued by pressing Enter after the command is typed in.


Installing Fedora Core 4

  1. Boot from the DVD or CD, and press <Enter> when you see the boot: prompt.
  2. You will then be asked if you want to check the media before installing. <Tab> to the Skip option, and press <Enter>.
  3. After a few seconds, you should see the GUI screen of Fedora's installation. Click Next. Choose your language and click Next. Choose your keyboard configuration and click Next again.
  4. Choose Custom Installation and click Next.
  5. On the next screen you'll have to define how you want your drive partitioned. I found that letting Disk Druid do the work is good for me, but you can choose to partition your system differently. It's your call. Just remember that you may have some large log files that you need to store.

    Choose Automatically Partition and hit Next. If this is a brand new drive, you may be getting a warning about erasing all the data on it, blah blah...
    You don't really care, since it's a new install, so let Disk Druid continue.

    You should then see a screen that asks you how you want automatic partitioning to happen. I always choose option two: Remove all partitions on this system. This will give you the most space in my experience.

    Click Next. You'll get a warning, so click Yes to get rid of it.
  6. You will then see your proposed disk partitioning configuration.
    Normally, Disk Druid will allocate around 100MB to /boot, about double your memory size to /swap, and the rest to / (slash. The root drive of your system, and where all other sub-directories, such as var, bin, etc, and tmp will be created).
    I know that this may be a bit confusing to a newbie, but explaining the directory structure in Linux is really beyond the scope of this document, so if you want to understand more about it, I suggest you get a good book :)
    Click Next.
  7. On the next screen you'll have the option to choose a boot loader password. By default, we will use the GRUB boot loader, and you can choose to put a password here so that only someone who knows the password could boot the machine. In my opinion, if your box is secured in your computer room, this is useless.
    Do you have boot passwords on your Windows machines? (do you?)
    Also, if you lose power, and your machine reboots, I think that it’s better for it to come up on its own, instead of waiting for you to enter the password. This is just my opinion. depending on your environment, you may decide to define a password here.
    Click Next.
  8. On the next screen you can define the IP address of the machine. If you know all the details now, go ahead and put them in: Click the Edit button, and uncheck the Configure using DHCP. Put the IP and subnet, press <Enter>, and fill the rest of the details in the main page.
    If you don’t have the details now, choose DHCP and see the end of this document for manual configuration later. I suggest that you update your machine’s IP address, hostname, and other networking preferences before you start installing Postfix.
    Click Next.
    Note: in one case, while configuring the network manually, my server was configured without a default gateway. If this happens to you, make sure to read Appendix A, and add the GATEWAY line to the NIC’s configuration file.
  9. On this screen you configure the firewall. You need to enable the firewall, allow SSH and SMTP, and disable SELinux.
    SELinux is some NSA security stuff that I'm still new to. It always breaks my SSH connections, so that's why I kill it. If you know a workaround which will enable SELinux and SSH at the same time, use it.
    Click Next.
  10. Select your time zone, and click Next.
  11. On the next window, you'll have to choose a password for the almighty root user. Make sure it's a secure password. Whoever has root has ownership of your machine, and this means that they can do whatever they want. Plain and simple.
    Click Next.
  12. On this window we'll select what to install. Note that this is not set in stone. If you feel comfortable removing some packages, be my guest and do it.

    Here’s the list by sections:


Desktops
:      

Choose either GNOME or KDE. I like GNOME.

Click on Details and uncheck all of the optional GNOME components.


Applications

Check Editors, go into the Details, and uncheck Emacs.

            Check everything under Text-Based Internet, except slrn and epic
            Uncheck Office/Productivity, Sound and Video, and Graphics.

 

Servers:         

Check Server Configuration Tools and all of its sub-components.

 

Development:

Check Development tools.

 

System:

Check Administration Tools.
            Uncheck Printing Support.

Uncheck Language Support.

 

Click Next twice to start the installation!

 

When the installation is done, the CD/DVD will be ejected, and you’ll have to click Reboot.


Errors During Boot

As of the writing of these lines, there’s an error that you’ll see right when the boot process begins. The following lines appear:

mknod failed to create /dev/console

mknod failed to create /dev/null

mknod failed to create /dev/zero

 

Please see this Bugzilla report to see if it was fixed: https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=157129

Update (07/17/2005): Bugzilla indicates that an update to the Kernel fixes this error. See the “updating the system” section below, and update your CD/DVD-installed Kernel!

After the Initial Reboot

After rebooting, you will have to set up a few more things:

 

  1. Click Next on the welcome screen.
  2. Accept the license agreement and click Next.
  3. On the next screen, make sure the date and time are correct, click on the Network Time Protocol tab, and set up an NTP server if you want. It can help a lot to have all your mail servers configured with NTP, so that all your logs have synced time-stamps.
    Click Next when done.
  4. You’ll find that we’ll not be using the graphical interface that much, but if you want to use it, you’ll probably want it at 1024x768 (the installation defaults to 800x600). Check that the Resolution button allows 1024x768, and select it. If it doesn’t, do this:
    Click the Configure button, and select Generic [CRT or LCD] Display, and press OK. The Resolution button will then include 1024x768, so select it, and click Next.
  5. On this screen you will have to create another user, since you don’t really want to work under the context of root. Just choose a good username with a strong password and hit Next.
  6. The next screen is for configuring the sound card. Click Next, since we won’t need it anyway.
  7. You don’t need to install anything from additional CDs, so click Next.
  8. Finish this part of the setup by clicking Next again.

 

Login to the System for the First Time

Login as root, and open a terminal window by using the main menu (like the “Start” menu in Windows), and then: Applications, System Tools, Terminal.

 

Issue the command ifconfig:

ifconfig

And press <Enter>.

 

See if you have an IP associated with the eth0 interface. If you don’t have an IP, check your cables and NIC.

 

Firewall Protection

I will not cover how to install a firewall on your server in this document. This server will be used as a mail-relay, spam filtering, and possible AV filtering server, nothing more. I think that making it a Firewall as well is a waste of valuable resources. Please make sure to create the necessary rules in your corporate firewall, to allow port 25 to this server, as well as any other necessary ports for Razor, etc, as you’ll see below.


PuTTY

PuTTY is a free SSH client. SSH is essentially a secured way of doing Telnet. At this point you can choose to continue working on the server directly, or to install PuTTY on your Windows-based PC, and SSH into your server instead!

 

Get PuTTY from here: http://www.chiark.greenend.org.uk/~sgtatham/putty/, then run it.

Select the SSH radio button when you see the main menu, enter your server’s IP in the “Host Name (or IP Address)” box, then put a name under the “Saved Sessions” box, and hit save.

 

From now on, every time you’ll start PuTTY, you can just choose the session name that you chose, and it’ll connect you to your server.

 

When connecting for the first time, you’ll see a security alert. Simply choose Yes, and you’ll be connected.

 

You can exit PuTTY by typing exit in the shell prompt. Don’t ever close PuTTY by hitting its window’s “X” button, at least not while you’re editing a file.

 

WinSCP

WinSCP is a very cool SCP (file-transfer) program that can greatly help you when you transfer files between your Windows-based PC, and your server. You can get it here: http://winscp.net/eng/index.php, and configuration of it is very easy. Just follow the defaults. You’ll have to give it your server’s IP address, as well as the user name and password for login. If you chose the “Norton Commander” look, it’ll give you two panes, one for your local PC, and the other for the remote server. You can then easily transfer files between the two.

Disabling Some Unneeded Daemons (Services)

Issue the command:

chkconfig <service name> off

Replacing <service name> with each of the following:
sendmail, apmd, cups, isdn, kudzu, netfs, nfslock, pcmcia, portmap, cups-config-daemon, and bluetooth.If your hard drives don’t support S.M.A.R.T., repeat the above for the smartd service as well.

Updating the System

Do you see that red ball with an exclamation point in it? It tells you that your system is not fully patched. So the first thing we’ll do is patch the system. I like to use the tool that came with Fedora, yum, to do the patching. Before we use yum, we need to import Fedora’s public key into our key ring. This is done to ensure that the packages that we’ll download are authentic, and came from trusted sources.

 

Type everything as shown. Remember that Linux is cASe sEnsItiVe.
In places that you see “- -“, remember that the two minuses should be typed without the space between them. It’s just that sometimes when I type -- in Word, it looks like one long minus.

 

Issue the following commands:

gpg --import /usr/share/rhn/RPM-GPG-KEY-fedora

rpm --import /usr/share/rhn/RPM-GPG-KEY-fedora


Now that you have Red Hat’s key in your key ring, you can download updated packages of Fedora.

 

Issue the command:

yum -y update

 

This will start downloading and installing new packages, and probably a brand new kernel. Take a coffee break.

 

After drinking many cups of coffee, issue the yum command shown above again, just to be sure that no update was missed. When you see a blue ball with a checkmark on it, your system is updated. You can repeat the process any time you want to update your system.

 

You can always issue the yum check-update command, to see what updates are available for update.

 

Changing the Language Preferences

We need to change the language settings of the system for SpamAssassin:

vi /etc/sysconfig/i18n

In the line that starts with LANG, change the “en_US.UTF-8”:

Put your cursor on the dot that’s in “en_US.UTF-8”, and press x 6 times, so that you’re left with “en_US”.

Save and exit the file.

Make vi Show Files in Color (use vim)

Argh! So annoying. The developers of FC4 changed something to make vi be the default editor instead of vim (VI iMproved).

We’re about to fix it below, but before we do, know that this change may cause you not to be able to run vi if your system ever crashes, and you need to run in emergency/single-user mode, and the /usr directory was not mounted for whatever reason. vim resides on /usr/bin/vim, so you can run it after mounting /usr in case of an emergency situation. If this is way to much information for you, don’t worry, and do the next steps anyway.

 

Edit the following file:

vi /etc/profile.d/vim.sh

 

It should look like this:

 

if [ -n "$BASH_VERSION" -o -n "$KSH_VERSION" -o -n "$ZSH_VERSION" ]; then

  [ -x /usr/bin/id ] || return

  [ `/usr/bin/id -u` -le 100 ] && return

  # for bash and zsh, only if no alias is already set

  alias vi >/dev/null 2>&1 || alias vi=vim

fi

 

Add a # sign in front of lines 2 and 3, so that it looks like this:

if [ -n "$BASH_VERSION" -o -n "$KSH_VERSION" -o -n "$ZSH_VERSION" ]; then

#  [ -x /usr/bin/id ] || return

#  [ `/usr/bin/id -u` -le 100 ] && return

  # for bash and zsh, only if no alias is already set

  alias vi >/dev/null 2>&1 || alias vi=vim

fi

 

And yes, in case you wonder, I know this can be done with Aliasing as well J

Optional: Configuring ls

I like the ls command to always show all files in a long listing, and in color.

Edit the /etc/bashrc file, and add:

alias ls='ls -al --color=tty' to the end of the file if you want it as well.

 

Downloading the Required Software

While we’re in the GUI, let’s download the installation sources that we’ll need.

Put them all under /usr/local/src. Note that you can also download the files to your Windows PC, and then transfer them to your server using WinSCP. Even though we can install some of this softw