Debian Anti-Spam Anti-Virus Gateway Email Server using Postfix, Amavisd-new, SpamAssassin, Razor, DCC, Pyzor, and ClamAV

This document is not recommend as a guide to upgrade a system from amavisd-new 20030616-p10 to amavisd-new 2.5.4. I designed it as a guide for myself to do a fresh install. Note that I do not install amavisd-new via the Debian package. There may be other versions of this document available. This document uses Debian etch software. Document originally created June 2005. Last revised 20 MAR 2008 by Gary V. The basic software used is Debian etch - Postfix 2.3.x - amavisd-new 2.5.4 - SpamAssassin 3.1.x. Due to the size of this document, please save it to your computer if you plan on using it more than once, then use that copy to view it subsequently. The "Change Log" is http://www200.pair.com/mecham/spam/20061118_changelog.html


Introduction
Document Description
Notes
Create Debian Installer CD
Debian Installation
Partition the Hard Drive
PuTTY and additional programs
The 2 minute vi tutorial
Verify System Settings
Change apt-get settings
Navigating the system
Create Firewall Rules
Disable Unnecessary Daemons
Configure the NTP daemon
Installing Programs
Postfix Configuration
Edit master.cf
Edit main.cf
Postfix Anti-Spam settings
Configuring amavisd-new
Pyzor, Razor and SpamAssassin configuration
Installing DCC
Local DNS cache
Test the Installation
Installing ClamAV
Tweaking Notification Settings
Back up critical files
Set up security reports
Set up intrusion detection
CPAN, Pflogsumm and trim_whitelist
Whitelisting, Blacklisting, Tweaking
Use the Rescue CD
Links, FAQs and such
Disclaimer


chart

Introduction:

Index
******************************************************
This document was inspired by a document originally created by Scott L. Henderson http://www.freespamfilter.org. It is rewritten to reflect a Debian installation and contains a considerable amount of additional information. In Scott's document, Red Hat Linux 9.0 was used.

Why this document exists:

There is a desire to control the flow of spam and viruses into organizational email systems. Many IT department budgets are tight and many administrators and executives are looking to Open Source solutions to reduce costs. To fight spam, you could buy an expensive appliance or proprietary software, but what if you could take a server you may already own and turn it into a better anti-spam tool than you could buy, without spending a dime on software?

I've found that many administrators of small to medium organizations (say, from 5 to 2000 users) don't yet have the knowledge, experience, or confidence, to build an Open Source system like this powerful anti-spam tool. This document is an attempt to address that situation. With little risk, one can try this spamfilter between an email server and the Internet. If you already have a gateway email server in place in front of your email server, you can place this server on your internal network between the 2 machines or on the Internet in front of your existing gateway. Given a choice however, it is much better to put this server ahead of any other servers. Even if you completely botch something, you can always just yank this system out of the loop and set about repairing it enough to retrieve any queued mail off of it. It is a nice way to get a taste of Linux and get your feet a little wet. I hope you will be as pleased as I have been with the results.

Although any version of Linux, as well as BSDs and other *nixen can (and are) used for this configuration, this document describes using the Debian 4.0 'etch' version (possibly mixed with other packages). Debian was chosen because it is free and has a loyal following. You may find however that Debian requires a little more proactive approach regarding security patches.

My email address is mr88talent at yahoo dot com. Support for the various programs used in this document is available from the mailing lists of the respective programs. There is also a forum available for this document and others like it at http://www.freespamfilter.org/forum/.

FAST BUILD BOXES

If you have built this system before, are an experienced Linux administrator, or for other reasons you want to skip all explanations and just perform the steps necessary to build this spamfilter, each major item that needs to be done is conveniently placed (where the Cat in the Hat keeps all his valuables):
IN A BOX

Commands to be typed in (or copied and pasted) at a command prompt will have a slightly different font than the rest of the text on this page:
like this

And those items that you either need to read, make a decision on, etc, in addition to being "in the box", will be italicized:
like this

Items that display on the screen will be displayed:
like this

It will be assumed that if you follow the 'fast build' boxes, you will understand how to do certain things without explanation, like getting to a command prompt, basic vim commands, knowing when to replace example values (like "example.com" and "example2.com") with your own when appropriate, etc.

******************************************************

Document Description:

Index
******************************************************
This Guide documents a step-by-step Debian GNU/Linux install using well-established Open Source software. The intended audience is a System Administrator currently running an email server that may or may not have ever used Linux.

This document will allow you to create an anti-spam email relay server. That is, there is no local mail delivery on this box. All inbound mail goes through this system. Spam is filtered out and re-directed to a specified mailbox ("spambin" in our example), or to the intended recipient, depending how "spammy" it is. Ham (non-spam) is passed on to its original intended recipients at your final destination mail server. Thus, a spam "filter" server.

This setup gives the system administrator control over spam, removing the need for end user interaction. In this configuration we will tag a small quantity of email as Spam> and forward it on to the intended recipient, but the vast majority of spam will be quarantined to a mailbox that we specify (spambin). Yes, with experience you can change this configuration. With this setup, if a user actually misses receiving an intended email, it is easy for you to find it and forward it on to them. It will be sitting in the quarantine area you have configured. The system is capable of using data from LDAP or SQL sources allowing per-user configuration but this document will not cover that aspect.

This system will work best when placed between a firewall and your Exchange server (any kind of SMTP/POP3/IMAP server) or you can sandwich it between your current gateway email server and your Exchange server if necessary (not a good choice). This machine will reject a lot of spam mail. If you place it behind another gateway server, that server will end up creating bounce notices, many of which can never be delivered (because spammers usually fake their address). That server will become what is known as a backscatter source and could eventually end up getting listed on blacklists. It is not good practice to accept a message you later bounce (especially if the sender is forged); if you are going to reject a message, it is best for all concerned to reject it immediately.

The design goal here is to filter and control spam and viruses originating from the Internet. The amavisd-new program was in fact originally written to be an interface between a mail server and various anti-virus packages. AMaViS is derived from "A Mail Virus Scanner". Local delivery of mail on this box could also be configured if desired, but this document will not cover that aspect. This system also has the ability to quarantine (or discard) any email that has attachments that you would like to ban from your organization. Since most email borne viruses come in the form of Windows executable attachments, this system could serve as a first line of defense, with the second line of defense in the form of your desktop Anti-Virus system.

******************************************************

Notes:

Index
******************************************************
1. This is not a "standard" Linux HOWTO doc. It is written with more detail, step-by-step, so that any Sys Admin who has not used Linux before can set it up. Hopefully it will be informative and useful to experienced Linux/Unix administrators as well.

2. Complete install as per this doc will require a minimum of 600MB of disk space. The system will additionally need whatever amount required for temporary mail storage, as email is spooling through, which depends on your email traffic flow. I can't hope to estimate that for you. It is not a huge amount however; the mail won't generally stay on this system long. If you configure your system to keep quarantined messages on this machine, you will need enough additional space to accommodate.

3. This entire procedure will take an experienced administrator about 7 hours the first time around. A newbie, roughly twice as long. With some experience under your belt, your second box will take half as long.

4. This doc will not cover hardware problems. It assumes you have Linux compatible i386/ia64/amd64 architecture hardware, including one NIC (network interface card). Generally, your hardware is most likely to be supported if it is neither too old nor too new in respect to chipset and processor technology.

5. Before you begin you'll need to know the IP address, netmask, and other IP configuration details to be used on this box. I won't be helping you with that.

6. You don't need a GUI like Gnome or KDE to build this box so we will NOT install one. It's a waste of 500MB on this particular machine. If you are new to Linux and want to see what they are like, put them on a box other than this one. If you absolutely insist on installing one, do it during the initial setup (using tasksel). I tried to do it after the fact and ended up with a mess. Having a GUI will not make installation or maintenance go faster or easier.

7. My instructions list using the vi (vim) text editor to edit text files. If you are more familiar with another text editor, feel free to use that. If you are used to a Windows environment, vi will seem difficult at first, but I will explain the basic commands you need to get things done. Be brave, you'll be fine, and when you're done, you'll be a little comfortable with the most common text editor in the Unix/Linux world.

8. In this doc, "example.com", "example2.com" and "example3.com" will be the fictitious example domains we'll be receiving mail for. You can receive mail for as many domains as you like with this system. Our example spamfilter mail server will have a host name of   "sfa".

9. If you are installing a single hard drive (non RAID) I suggest you start this project with 2 identical hard drives. This however is your choice. You will spend a considerable amount of time creating this server and the easiest, most reliable, and most cost effective way to back up this server is to duplicate the hard drive. I suggest hard drives of at least 4.3GB but it's much better to start out with a pair of modern (fast) hard drives. If you happen to have a pair of identical computers kicking around, with identical network cards, so much the better. I like spares. The hard drives will be wiped clean of all partitions. Use only known good, error free hard drives. This is not the only means of saving yourself a lot of work should your hard drive fail. You could simply ftp the most critical files to an ftp server of your choice. If you are interested in a RAID1 setup, see http://www200.pair.com/mecham/raid/raid1.html

10. You will need to create at least two new mailboxes on your Exchange server to hold the quarantined spam and banned files. In this document, these mailboxes will be called "spambin" and "banned"'. You will also need mailboxes named "root" "postmaster" "abuse" and "mailer-daemon". These can be aliases for mailboxes that currently exist, or you can create new mailboxes for them. You may also wish to create a separate mailbox for quarantined viruses; I use "virii". You might want a separate mailbox for "postmaster" because you may receive NDRs there. A NDR, or "Non Delivery Report" is a type of DSN (Delivery Status Notification). The "root" mailbox will receive important system information. The "spambin" and "banned" mailboxes must be monitored, and if "ham" (non-spam) is found, it must be forwarded to its intended recipient(s). Consider whitelisting the sender, so you don't have to worry about it again. With a little experience, you will find ways to quickly glance through the spam and delete it in bulk. You may want to empty the trash on exit. If you create a "virii" mailbox, that must also be monitored.

11. This system can also be configured to discard spam by simply changing one line in a configuration file but this is not appropriate in all organizations. SpamAssassin assigns a score to each email depending on how spammy it calculates it to be. If you choose to discard spam, then you should only consider that option for spam that scores a 14 or higher. There are a couple of ways we can do this, and I will discuss them later.

12. When I refer to the Exchange email server, this term is synonymous with "your current email server" or "your current SMTP/POP3/IMAP server". In other words, it's not specific to Microsoft Exchange.

13. You could build more than one of these boxes and use the second one as a secondary MX email server. Allocate an unused IP address to the secondary server and add a new A record and (secondary) MX record in your DNS records. Please note that this document does not cover issues such as MX records or changes to DNS records or adding reverse DNS records. It assumes that if you have set up your own email server you will have some understanding of these issues. Your ISP may offer assistance here. Be aware that changes to DNS records if improperly done may result in the loss of mail. It can take days for other DNS servers to recognize changes. You need to gain enough knowledge to understand the implications of DNS record changes. If this server is on an internal network, sandwiched between your existing email gateway server and your Exchange server, then no Internet DNS changes are required. In general, don't delete any existing DNS records!

14. There are many ways this spamfilter could be incorporated into your existing setup. I would like to give one possible scenario. Let's say you have one Exchange server handling all your email. You have an MX record set up for it with a priority of [10] and you managed to set up a reverse DNS record for it and everything is working fine. Take one of your unused public IP addresses and assign it to your new spamfilter. Once our new spamfilter is working as it should, create a new 'A' record for it 'sfa' and a new MX record with a priority of [5] 'sfa.example.com.' which will make it your new primary Mail eXchanger. Your Exchange server will now be your secondary Mail eXchanger. After the DNS records records have been in place for at least a week (this gives all the DNS servers time to eliminate their cached records) and the system is running well, you may now configure the Exchange server to only accept connections from your spamfilter(s) and your internal network (it's best to do this by blocking inbound port 25 access to the Exchange server at the firewall/router). By this time the only mail that should be coming in directly to the Exchange server is spam, because spammers love to deliberately send mail to secondary servers. The spamfilter will be configured to send all of its mail to the Exchange server. We want to leave the Exchange server's DNS records alone so we can quickly re-enable Internet mail to that server in case our spamfilter should fail. If you would like an additional backup email server, just build another one of these and set it up with a priority [7] MX record.

15. It is extremely important that this box is thoroughly tested before being relied upon to handle large quantities of mail in a production environment. When building the system, send test emails through one at a time and evaluate what has transpired. Get intimately familiar with the mail.log file. Turn up the level of debugging in amavisd-new. Run amavisd-new in debug mode and monitor the activity. Monitor memory usage using the 'top' program. I will explain how to do these things as the document progresses. The following comments are personal interpretations/observations and may not be technically correct: I have seen on several occasions that even on a properly set up system, when the system is under load, there are memory allocation issues. Some of the processes tend to temporarily allocate enough memory that some of the 'swap' memory is allocated. This memory is then released for use by other processes. If an amavisd-new process begins using swap memory, it runs so slowly that it essentially becomes unavailable to Postfix. The mail then begins to build up in the queue waiting for another shot at it later. This makes matters worse because there is that much more mail to deal with. The system eventually chokes and you are left with thousands of messages in the queue. Lessons to learn here: if this system goes down and you need to take this system out of the loop, make sure you have another system (your original system, if nothing else) in place to accept mail until you get the problem solved. You can disable the content filter (amavisd-new) and requeue the deferred mail and Postfix will at least get the mail delivered and off your system. If you are filtering for multiple domains, start by having only one (least busy) domain have its mail sent through our spamfilter and keep an eye on things. Build from there. If your system exhibits this sort of behavior, it could be an indication you need more horsepower under the hood (or simply more RAM) or your system is not tuned properly.

16. Minimum hardware requirements:
For a small system with a light load (a couple emails per minute, or 2000 messages per day at peak) I suggest a Pentium II 450Mhz and 256MB RAM absolute minimum (384MB gives you a little breathing room). At 10,000 messages a day a 1Ghz PIII with 768MB RAM would be more appropriate. At 50,000, a modern dual processor machine with 2GB RAM should be a decent choice. Amavisd-new appears to use about 53MB per child process (parameter $max_servers) and will use 158MB right out of the box (one master and 2 child processes) and ClamAV will add around 15MB to that. If you configure your system to use more instances of amavisd-new, allocate at least 53MB for each additional instance (68 if you use ClamAV). Amavisd-new can reach 100MB per process if you use a lot of additional SpamAssassin rule sets and/or have large black/white lists. Generally speaking, a fast hard drive and adequate RAM may show more of a performance improvement than a fast processor will, but an adequate CPU is also necessary. Fifty percent more ram than you need is not a bad idea. The programs that run on this server are disk intensive and CPU intensive. A slow hard drive will make this system perform poorly. In this setup we forward quarantined email to another server. If you plan on keeping quarantined email on this server you will need a large enough hard drive to accommodate. You will need a known good floppy drive, a CD-ROM drive and of course, a connection to the Internet. It’s a good idea to have hardware that you don’t plan on changing. Your spamfilter should ideally be in its final form. Adding additional memory later is fine. If you get errors during installation that appear to be hardware related, find other hardware and start over. If you have a new motherboard, you may or may not get very far. Our Linux kernel may not support every new motherboard chipset out there. If you have an ancient NIC card, or one of a new design, you may not get very far either.

17. Benchmarking:
Sorry, I do not have benchmarking data for high-end use, such as at very large companies or ISPs, but I am aware of several small ISPs that currently run this configuration. The software components in this doc are all designed for high capacity and I would expect them to scale up very well. The 2 main executable programs used herein, Postfix and amavisd-new, both have configurable throttling and performance settings. They are also mature products, with a proven track record and a large following of users. SpamAssassin, with all the work it has to do, fetching information off the Internet on the fly, matching its rules to the content of the messages and such, will tax a machine quite a bit. If you add antivirus filtering, this will also put some pressure on our spamfilter. Large ISPs need powerful multi processor machines and fast SCSI hard drives to make this work well. I have heard of sites processing millions of messages a day using a cluster of 15 high powered multi processor machines. Mark Martinec has also written a paper that illustrates the capacity of a single high power dual processor machine http://www.ijs.si/software/amavisd/amavisd-new-magdeburg-20050519.pdf. Mailscanner is a product similar to amavisd-new. Here are some samples of servers used with Mailscanner: http://wiki.mailscanner.info/doku.php?id=maq:index#setup_examples.

18. This document was created from a Windows user perspective. UNIX/Linux users should have little problem translating Windows specific activities to your environment. I suggest you create a new folder on your computer, preferably in the root directory of drive C: and call it "debian". This folder will be where all the work files we use will be stored. I would like you to save this html document there now and then open it up again in your browser. We are going to customize this document to make things easier for you. Once we have the spamfilter computer up and running you will do the entire configuration by remote control from the comfort of your Windows computer. Portions of this document can be copied and pasted into the spamfilter computer. I would like you to customize this document by doing a search and replace of the elements such as the spamfilter's IP address and hostname. I suggest using WordPad to edit this document. If you have a plain text html editor you like, you may use that instead. Avoid using any editor that modifies the html code. Once you open it in your editor you will see instructions at the top of this document. Go ahead and do that now.

After you edit the document, it might be a good idea to print it out so you can check things off as you complete them (it's about 80 pages).

19. Precautionary note: Be very cautious obtaining any and all software from links on these web pages. Spend some time looking at the URLs on the web pages that pop up. Verify the web sites are legitimate. You could be reading a forgery of this document designed to cause malice. The websites that you link to could be hijacked. Read the disclaimer.

20. Every link in this document opens in a new window, so if it appears nothing happens when you click a link, take a look at your Taskbar.

21. Assuming you are not using a RAID configuration and would like the ability to clone your hard drive:
If you have an IDE CD-ROM drive, set the jumper on the CD-ROM drive to SLAVE and install the CD-ROM drive as the secondary slave. Install the CD-ROM drive so it is in the second position of the data cable; so the primary part of the cable sets loose on top of the drive. If you have a tower case, place the CD-ROM drive in the slot that is at least one down from the top. The reason we are doing this is we want to be able to place a duplicate hard drive in the top position. This drive will not be plugged in during the installation. We will only plug it in when we want to duplicate the primary hard drive. This drive will be used to back up the entire system on occasion. Leave the cover off the case while we build the box. In the future you may wish to purchase one of those mobile hard drive racks. This is why we left the top slot free. If you have a SCSI hard drive, well, hopefully you know what to do as far as jumper settings go. This is all optional, but recommended. It would be nice to have some means of quickly recovering the system after a catastrophe.

While you are building the box, it would be a good idea to back it up when you have reached a major milestone. We can simply place the duplicate drive on top of the CD-ROM drive and plug it in (with the power off, of course). Set your BIOS to auto detect your drives (if you have that option). There are two simple methods I use to duplicate disks, one is to use dd. It makes an exact duplicate of your hard drive bit by bit, sector by sector, even empty ones. This is why (1) your hard drives must be identical; (2) they must be error free. dd does not work well if both of these conditions are not met. dd is also painfully slow, it can take hours for a large (40GB) disk and some people say it is not a reliable way to clone a hard drive. Each hard drive has a 'defect table' and this method of cloning will overwrite that table on the new drive. One other alternative is Norton Ghost 2003 or the Enterprise edition. Earlier versions will not work. Version 8 will work great if you are fortunate enough to have a copy. See Ghost compatibility with Linux. Ghost has the option to clone a drive sector by sector similar to what dd might do. Like dd, the disks should be identical when using this method. At the very least, the destination drive should be the same size or larger and the geometry should be similar. Going to a smaller drive using this method would fail. If Ghost complains that your hard drive has errors, I suggest you run   shutdown -r -F now   and let it reboot. When it starts back up it will run "fsck" which is the conceptual equivalent of "chkdsk /f" in the Windows world. Ghost 2003 comes with SystemWorks 2003 or often comes with motherboard software. Ghost 2003 also works in (the recommended) normal mode but after the disk is cloned the boot record must be repaired on the cloned drive by first booting to a rescue disk. Actually, I have had great success using the -ib (Image Boot) setting. It appears to make an exact duplicate of the boot sector, then does a regular clone operation on the remainder. There is other software out there that has the ability to clone Linux hard drives. I’m just used to Ghost.

Let’s talk about dd. Here’s an example of how it can be used. Boot up using the etch CD, answer the first few prompts (Language, Country, Keyboard), let it discover devices (but go no further!), then use [Alt]+F2 to open a console. Log in as root. Then, with both drives installed, issue the command:

dd if=/dev/hda of=/dev/hdc bs=8192
This assumes IDE hard drives. Type this very, very carefully. Then wait a long, long time. Your disk drive LED should be lit solid.

if = input file, of = output file. IDE disks are numbered hda hdb hdc hdd - primary master, primary slave, secondary master, and secondary slave - respectively. SCSI hard drives are sda sdb sdc etc. (depending on jumper settings - so take care that sda remains sda when you install a second drive). Any time you clone a hard drive, you should test the cloned drive. If it boots up, reboot it by using   shutdown -r -F now   to repair any potential problems.

22. Linux, Postfix and amavisd-new are flexible, complex systems. There are innumerable ways to configure a spam filtering server like this one. This document will not attempt to teach you everything there is to know about Linux, Postfix, SpamAssassin and amavisd-new, nor are the instructions I provide meant to give the impression that this is the best way to configure this device. This box meets MY needs and hopefully will provide a solid base for others to work with. It is my hope that this document will provide a degree of familiarity with these programs sufficient enough to enable you to resolve problems as they arise and enable you to reconfigure the system to meet your needs. If you need help with problems, or just want to tweak the system to meet your particular needs and you need help doing so, the mailing lists for the various programs are your best source. When using mailing lists, state the versions of the programs you are using; try to state the issue in a concise manner and provide examples when examples are necessary. Search through the mailing list archives to see if your question has been answered before. I feel the biggest flaw in this document is that you will learn only a little about Linux and the aforementioned programs and you know what they say: a little knowledge is a dangerous thing. If you are new to Linux I suggest at the very least you purchase a Linux Pocket Guide or equivalent to have on hand. Here is a 16 page PDF on Unix command line basics.

23. This machine will have to resolve a lot of IP addresses and read a lot of DNS records. If it takes a long time to retrieve an answer from a DNS server, this delay could affect the performance of this box. It is much better to have a local caching DNS server available than not. You may have a local proxy server capable of caching DNS queries or a server on your network running a true DNS server like BIND or Windows 2000/2003 DNS server. If you do, use one of these as your primary name server. I provide instructions in this document to install a local DNS cache on this machine if you do not.

24. So what do these various programs do? Postfix is a powerful and flexible MTA. In its most basic configuration it receives and routes email. We will configure it to use amavisd-new as a content filter. Postfix will listen on the standard SMTP port 25 and any mail that comes in on that port and is not rejected will be sent to amavisd-new on port 10024. Amavisd-new will process it and send the mail back to Postfix on port 10025. Postfix will then relay it to the intended recipient(s) on another mail server. Amavisd-new acts like a specialized MTA. To prevent the loss of mail in amavisd-new, amavisd-new will not actually say it has accepted a message from Postfix until it has returned it to Postfix (or bounced or discarded it). In our case, amavisd-new will load SpamAssassin and use it as though it is part of the program itself. It will also call ClamAV (clamd or clamscan) to scan email for viruses. SpamAssassin will query Pyzor, Razor2 and DCC servers and the result of the queries may influence the score that SpamAssassin produces. SpamAssassin is a sophisticated system using a number of means to identify spam. It uses hundreds of its own static and dynamic tests and it queries other servers on the Internet in order for it to produce a spam "score". The higher the score, the more likely the message is spam. Razor, Pyzor and DCC are each different in the way they work, but they have at least one thing in common: they are collaborative mechanisms. Computers all over the world feed them spam or spam signatures. If they receive the same spam signatures from many different sources, it is assumed that the message can in fact be considered spam. SpamAssassin checks each email to see if it appears in any of their databases. SpamAssassin also queries a number of other real time blacklists (RBLs) and several URIDNSBL servers. SpamAssassin sends the URLs found in the message body to URIDNSBL servers to see if they have been blacklisted. These are also collaborative mechanisms that are manually reviewed by humans. SpamAssassin merely scores the email. We configure amavisd-new to take various actions depending on the score. I have found a paper that further describes the actions of these programs and how it all fits together: http://www.giac.org/practical/GSEC/Greg_Williamson_GSEC.pdf

******************************************************

Create Debian Installer CD:

Index
******************************************************
There are, at any given time, three versions of Debian. They are 'stable', 'testing' and 'unstable'. At the time of this writing 'stable' is named 'etch', 'testing' is named 'lenny' and unstable is always named 'sid'. The Debian etch 4.0r3 netinst CD-ROM is currently the method chosen to install the operating system. A "Business Card" CD is another possible choice, but is some times problematic due to "package churn". It's also possible to use floppy disks.

You need a CD-RW drive and CD burning software on your PC to create the CD from an ".iso" file.
Make a new directory on your Windows computer and call it 'debian' or something. Then download the latest version of the Debian installer for 'etch' and save it there. Go to: http://www.debian.org/releases/etch/debian-installer/. Read the errata while you are on that page. One interesting errata is http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=401435.

Note that there are etch 4.0r3 i386 or etch 4.0r3 ia64 or etch 4.0r3 amd64 CDs available from this location but I have only tested this setup using the i386 CD (32bit). By default it installs the Linux kernel version 2.6.18.

Create a CD from the image using your CD burning software. When you label the CD include the creation date of the software. I use Roxio 5.0 Easy CD Creator. From the Data CD Project window I choose File -> Record CD from CD image. For Nero 5 Burning ROM, choose File -> Burn Image after getting to the data CD window (ISO).

******************************************************

Debian Installation:

Index
******************************************************
Set the BIOS in your computer to boot from the CD-ROM drive if necessary. This may be a good time to check the date and time set in the hardware clock. If for any reason you cannot create the CD or you cannot boot from the CD, you may be able to boot from Debian Installer floppies. A separate document http://www200.pair.com/mecham/spam/installer-floppies.html provides instructions on creating the Installer floppies. Before you start the installation, you may need to know what brand and model your Ethernet card is. You may need to know what chip set the card has. I was unable to install a 3Com 3c509 ISA card. The fun part of the installation is that no matter how I describe the process to you, it may be different when you do it. The Debian installation process somewhat follows a linear pattern, but I cannot guarantee what screens will come up. In general, if you are asked questions during installation, the installer guesses what the most appropriate response would be, and it usually is what we want. If things don't go well and you need to start over, I strongly suggest you delete everything off the hard drive during [Partition a hard drive]. Starting with a clean slate helps a lot.

Additional information on the Debian Installer is located at http://d-i.alioth.debian.org/manual/en.i386/apa.html

The main objective of the Debian Installer is to gather enough information to enable it to install the Debian base system. It needs to know what language to continue in, what keyboard you are using, what network hardware you have (it should figure this out automatically), and what your network settings are (we don't want it to figure this out via DHCP). We will also have to configure the partitions on the hard drive at this time so we have a place to put the software that is installed.

We are going to erase the hard drive so make sure you don't have any data on it you might need. Boot up the computer using the Installer CD or the Installer floppy #1. If you use the floppy to boot up, it will prompt you for remaining floppies. I recommend using the CD-ROM. The instructions below pertain to the CD-ROM method in the default "ask as few questions as possible" mode. When the system boots up to the Debian screen, simply press [Enter] at the boot: prompt.

[ !! Choose Language]
This determines the language of the installer and picks a keyboard.
This installation has only been tested with
English - English
[Choose country, territory or area]
Choose what is appropriate

Unplug the ethernet cable.

[! Select a keyboard layout]
American English selects a standard qwerty keyboard.

There will be a few screens of activity, then this will come up:
[Configuring the network with DHCP]
Hit [Cancel] because we want DHCP configuration to fail.

Plug the ethernet cable back in.

[Module needed by your ethernet card]
If you see this menu, it only means one thing. The Installer does not recognize your Ethernet card.
Look through the list; the majority of cards that are supported will NOT be on the list, this is a list of somewhat obsolete or possibly bleeding edge cards, not the majority. If it does not find your card, try another NIC Card. The machine I am building right now has an old 3Com ISA PnP 3c509, and it's not working, possibly because PnP may not be supported this early in the game, or because there is a bug in the installer. This is going to be an email server, so a reliable NIC card is important. If you have and old ISA NE2000 compatible card you can use the "ne" driver but you will need to know the interrupt and I/O address beforehand. If you have a problem, the fastest way to solve the problem may be to replace the card with another model.

[!! Configure the network]
Network autoconfiguration failed

We wanted that to happen, simply press:
[Continue]

On the next screen, choose the default of:
[Configure network manually]

[!! Configure the network]
Make sure Num Lock is on!
[IP address:]
111.111.111.111
[Netmask:]
255.255.255.x
[Gateway:]
333.333.333.333
[Name server addresses:]
444.444.444.444 555.555.555.555
[Hostname:]
sfa
[Domain name:]
example.com

******************************************************

Partition the Hard Drive:

Index
******************************************************
The disk partitioning software that comes with this version of the Debian Installer seems to be geared toward novices and as such makes a lot of assumptions in order to make partitioning easy. However, if you want to deviate from what the software provides, it is somewhat cumbersome. At this point you can play with the partitioning software all you like. If you have problems, simply erase the disk and start over.
[!! Partition disks]

[Partitioning method:]
Choose Guided - use entire disk

[Select disk to partition:]
Choose what is appropriate

[Partitioning scheme:]
You are free to choose any of the three partitioning schemes provided but we need at least 1GB of space for each data partition. If you choose the [Separate /home partition] or [Separate /home, /usr, /var, and /tmp partitions] method of partitioning, ideally you would have 4GB or more for either the /var partition or the /var/spool partition respectively.

If you are building this with a small drive (not recommended) or simply want to maximize disk space (like I often do), choose

[All files in one partition]

For a larger drive you may optionally choose:
[Separate /home partition]

Then arrow up and change the "Mount point:" of partition "#6 logical" from /home to /var
Here is an example of what the finished product could look like:
IDE1 master (hda) - 10.0 GB Maxtor 5T010H1
    #1 primary   2.8 GB B f ext3  /    (bootable) (root partition)
    #5 logical 353.7 MB   f swap       (swap partition)
    #6 logical   6.8 GB   f ext3  /var
The same drive using and modifying the [Separate /home, /usr, /var, and /tmp partitions] partitioning scheme: It took me about 10 minutes of playing with the software to figure out how to modify what the partitioning software came up with, this may provide a little better performance (due to reduced file fragmentation) but will also waste more disk space. You need a 6GB or larger drive and a little patience to do this.
Change the mount point of "#1 primary" from / to /boot
Change the mount point of "#5 logical" from /usr to /
Change the mount point of "#6 logical" from /var to /var/lib (Enter manually)
Delete both partitions #9 and #8, then recreate logical partitions #8 and #9 from the free space and change the mount points to what is illustrated below.

Each data partition should be at least 1GB as shown. The /var/spool directory is where our mail queues will be, so it would be desirable to make it 3GB or larger. If you store quarantined mail on this system then you need to make whatever partition it's stored on is adequately large. The default for amavisd-new is /var/lib/amavis/virusmails so in this next example the /var/lib partition should be large.
IDE1 master (hda) - 10.0 GB Maxtor 5T010H1
    #1 primary 279.6 MB ext3 B f /boot     (bootable)
    #5 logical   3.6 GB ext3   f /         (root)
    #6 logical   1.8 GB ext3   f /var/lib
    #7 logical 386.6 swap      f swap
    #8 logical   1.0 GB ext3   f /var/log
    #9 logical   3.0 GB ext3   f /var/spool
Once you have what you like, choose
[Finish partitioning and write changes to disk]
[Write changes to disk?] [Yes]

[! Configure time zone]
[Select your time zone:]
Simply choose what is appropriate.

[! Configure the clock]
[Is the system clock set to UTC?]
If this comes up it may be an indication the system clock is set to UTC. I prefer to set the system clock to local time so I [tab] over and answer [NO] but this is up to you.

[!! Set up users and passwords]
This will ask for root's password and allow you to create a "normal" user and a password for that user. Watch your [Num Lock] status. Use really good passwords and don't forget them. Please add one, and just one, normal user here. If you plan on storing mail locally on this machine (not documented here), or even if you don't, create a user who's main purpose in life might be to hold root's mail. I suggest calling the user myroot or something similar. Keep in mind that all the best hacker tools run on Linux. If a hacker gains root access to this box, your entire network is history.

[Installing the base system]
Wait....

[! Configure the package manager]
[Use a network mirror?]
Choose [Yes]
[Debian archive mirror country:]
Choose your country
[Debian archive mirror:]
Choose a mirror near you (mirrors.kernel.org works very well in the US)
[HTTP proxy information]
(configure if needed, otherwise leave unconfigured)
Scanning the mirror...

[! Configuring popularity contest]
You decide if you would like participate.

[Debian software selection]
[Choose software to install:]
This is 'tasksel'. You only want to select 'Standard system' here (nothing else). Use the [spacebar] to deselect 'Desktop environment'. Then, simply [Tab] over and select [Continue]. (I heartily recommend you do not run a GUI; however, if you absolutely insist on doing so, leaving 'Desktop environment' selected is the way to install it).
Software will download now. I hope you have a fast Internet connection. What software we don't have now, we can easily get later. We are trying to keep this system somewhat clean. We will use apt-get to install most software after the fact. Some software may also be upgraded, and as a result, you may be asked some questions. When asked a question, usually the default answer will be the correct answer.

This section should not show up, but just in case it does:
[Configuring console data]
IMPORTANT! choose "Don't touch keymap"
You chose one earlier whether you knew it or not and choosing
any keyboard here may remove the keyboard mapping
and you may not be able to get it back without starting the installation over!


This may not come up, but in case it does:
[Configuring Exim v4 (exim4-config)]

[General type of mail configuration:]
choose [no configuration at this time]
[Really leave the mail system unconfigured?] [Yes]

[Root and postmaster mail recipient:]
The "normal" user we added earlier will display here. This is fine, so simply accept this. Since all mail will be relayed to another server, this setting will actually end up being ignored. However, if you configure your system to store mail locally, all of root's mail will be redirected to this "normal" user's mailbox. This is necessary because you typically cannot access root's mailbox remotely.

[! Install the GRUB boot loader on a hard disk]
[Install the GRUB boot loader to the master boot record?]
If you would like the install the GRUB boot loader choose [Yes]
If you would like the install the LILO boot loader [Tab] over and select [Go Back]
Then select the 'Install the LILO boot loader...'
[Finish the installation]
Remove the CD or floppy when prompted, then hit [Continue] This will reboot.

Once you get the login prompt, login as root and issue the following command:
apt-get install ntpdate ssh vim gnupg

It may ask you to insert the installation CD; do so, then please remove it afterwards. We installed ntpdate so we can set our clock to the correct time. Note that if you have problems communicating with the download server (download seems stuck at [0%] - nothing seems to be happening for a long time), you can use [Ctrl]+c to break out of the communication session then try again. You should not use [Ctrl]+c when software is actually installing however, doing so could trash your system.

Enter the following command:
dpkg-reconfigure locales

[Configuring locales]
You use [PgUp] [PgDn] [up-arrow] [down-arrow] [tab] and [spacebar] to navigate and select.
The etch installer software installed en_US.UTF-8 UTF-8 on my system. I suggest you install the en_US ISO-8859-1 locale (in addition to any other ISO-8859-x locales you may require). If you need to change the locale, or add additional locales, use the [arrow] [spacebar] and [tab] keys. A UTF-8 locale should not be used as the default system LANG (set in /etc/environment or /etc/default/locale), SpamAssassin and amavisd-new may have problems if you do. You should keep the UTF-8 locale in addition to the ISO-8859-x file or Perl may complain.

[Which locale should be the default in the system environment?]
I suggest you do NOT choose [None], I suggest you choose [en_US] or other non UTF-8 locale (an ISO-8859-x locale).

We need to make sure we have a keymap file:
ls -l /etc/console

This lists the contents of the /etc/console  directory. You should see a file named "boottime.kmap.gz"
If you get "Total: 0" then we have no keymap file.

If, and only if, we have no keymap file, run the command:

dpkg-reconfigure console-data

And choose [Select keymap from arch list]
Follow the prompts that apply to you and when the program exits check again to see if there is now a file called "boottime.kmap.gz" in the /etc/console  directory.
If the file is not there, reboot and try again. We cannot continue until a keymap file is installed. Worst case is we would have to start the installation over again!


Note that you can use the [up-arrow] key to recall previously entered commands (which can then be edited and executed).

Once you are back at the shell prompt, reboot the system with:
reboot

This is the end of the basic Debian installation.

If you don't feel good about the way things went, or you would like to experiment with one of the other methods of installation, this would be the time to start over from scratch!


******************************************************

PuTTY and additional programs:

Index
******************************************************
Now turn the monitor off and head on over to your trusty old Windows computer. We are going to configure every thing else from there!

You should have this document open in a window on your Windows computer because we are going to use a Windows SSH client called PuTTY to operate our spamfilter remotely. I am going to save you a lot of typing because you are going to select text with the mouse, copy it to the clipboard with [Ctrl]+c and then paste it into the PuTTY window with a right-click of the mouse. This will save you a ton of typing.

Download putty.exe from somewhere like: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

Place putty.exe on your desktop, open it up, select SSH, input the IP address of the spamfilter then enter a name for your session in the Saved Sessions box. In the Category window, expand Terminal and click on Features. Check the box "Disable application keypad mode". Just below this in the Category window, click on Window, and increase "Lines of scrollback" from 200 to 400. Click on Session (at the top), then Save. the "Disable application keypad mode" enables us to use the numeric keypad when using vi.

When you use PuTTY again, simply double click on the saved session. Make sure you are at a command (shell) prompt before exiting PuTTY. You can log off the PuTTY window by issuing the command 'logout' or 'exit' or [Ctrl]+d.

If you are selecting some text to paste onto the Linux command prompt (the bash shell), you normally should not select the empty line below the text we are selecting. If you do, this has the same effect as hitting the [enter] key when it is pasted into the PuTTY screen. Sometimes this is desirable. If you select only to the end of the text, you will have the opportunity to review what was pasted before you hit [enter]. Make sure the command line is empty before you paste something into it.

If you are editing a configuration file (we will use the vi editor to do that), you may select multiple lines to copy and paste. To insure there is a newline character at the end of each line I suggest extending your selection to the empty line below the text you are selecting. I will provide empty lines below any text that ends up getting pasted into a document we are editing with vi.

Some of the text in this document will have to be edited either before or after you copy and paste it into the PuTTY window. If you have not already done so I recommend you save this document as a text file or an html file and do a search and replace of key items like your domain name and IP address, then use that document to continue. I suggest using WordPad or your favorite plain text HTML editor to edit this file. Do not use a program that will modify the HTML code. If you open this document in WordPad there are instructions at the top of the page. Once your changes have been made, open the saved document in your browser. You will now have your own semi custom document.

Note.
Your [Home] and [End] keys will work when editing a file using vi, but will not work at the command prompt (you can use [Ctrl]+a and [Ctrl]+e for this).

Open up a PuTTY session now and log in as root.
The command prompt at the bash shell will look something like:
sfa:~#
The ~ (tilde) represents our home directory, and because we logged in as root, our home is /root

This would be a good time to also download and install WinSCP. WinSCP is a great GUI file browser that lets you transfer files between your Windows machine and your new Debian box. You can also edit files on your Debian box from your Windows machine using WinSCP's editor. I suggest when you save sessions you leave the password blank so you are prompted for it each time you log in.

Please install and configure PuTTY and WinSCP per the notes above.

Important note: The machine is very vulnerable at this point. Any time you are not working on the spamfilter, you should unplug the ethernet cable! This machine should be connected to the Internet only when necessary to configure it. We need to get all our security measures in place before it "goes live". You will need to leave it plugged in to complete the installation however. If you are familiar with editing files on a Linux system, it might be a good idea to jump ahead to "Create Firewall Rules" and then return here to continue.

******************************************************

The 2 minute vi tutorial:

Index
******************************************************
We are going to use vi (vim actually) to do most of our editing. Fortunately we only need to learn a few commands to be able to accomplish our tasks. There are 3 operating modes in vi. There is the "Command" mode, the "Write" mode and the "Command line" mode. When you first open a file for editing, you are in Command mode. You change to Write mode by entering the letter "i", (short for "insert"). You can edit text pretty much as you would expect in Write mode. You exit out of Write mode and return to Command mode by hitting the [Esc] key. There are many commands that can be learned in Command mode but we only need to learn two more in addition to "i". Those commands are ":" (a colon) and "/" (a forward slash). The colon is used to enter the third mode, the Command line mode and the slash enables the Search command. When you are in Command line mode, you will see a colon at the bottom of the screen. Here is a list of commands we will use while in Command line mode:

:q    quit (provided you have not made any changes) By the way, the lower case q is used often in *nix as a way to exit a screen.
:q!   exits vi and discards changes (great when you trashed the file and just want to start over!)
:wq   saves the changes and exits vi (write and quit)
:w    saves the current changes but does not exit vi (write)
And in command mode:
G    The capital "G" Goes to the bottom of the page (very handy)

And here is how the Search command works:
/text_to_search_for   moves the cursor to the first occurrence of     text_to_search_for

Once the first occurrence of the text we searched for is found, use a lower case 'n' to find the next occurrence.

That's all we need to know for now!
If you would like a cheat sheet for additional commands: http://www.fprintf.net/vimCheatSheet.html and http://amath.colorado.edu/computing/unix/vi/

******************************************************

Verify System Settings:

Index
******************************************************
We need to take a look at a few important files to make sure they are accurate.
vi /etc/resolv.conf

Make sure our domain name is at the top, in the form:
search example.com

The file should look something like:

search example.com
nameserver 444.444.444.444
nameserver 555.555.555.555

Repair it if it is not. (Use "i", then edit it).
If you made changes, Exit the file with [Esc] : wq
If you did not need to change anything, Exit the file with [Esc] : q

vi /etc/hosts

The top of file should look something like:
127.0.0.1           localhost
111.111.111.111     sfa.example.com    sfa
Repair it if it does not. Remember, use "i" to insert. Since we are here, you might as well add any other hosts you would like our spamfilter to know about. I suggest you (at least) put your internal mail server(s) here. Simply append any other entries to the bottom of the list.

If you made changes, Exit the file with [Esc] : wq
If you did not need to change anything, Exit the file with [Esc] : q
If you have a mess on your hands, Exit the file with [Esc] : q! and try again.

Since you are using an etch CD, our default language will be an UTF-8 locale. We want our system wide language to be an ISO-8859-x (non UTF-8) locale. You can set the language in /etc/environment (if it exists, otherwise it is set in /etc/default/locale). This file is read when we log in. We need to use a non UTF-8 locale so characters will appear as we expect them to and to avoid other problems. It is best to run amavisd-new in a non-UTF8 locale environment. The 'dpgk-reconfigure locales' program previously automatically updated /etc/environment, but it no longer does when using the etch version so we are going edit it manually (it now updates /etc/default/locale). Make sure you have installed a corresponding ISO-8859-x locale for the UTF-8 locale we are going to change:

cat /etc/environment

If the above returns "No such file or directory", then the setting is in /etc/default/locale and you can skip editing this file, otherwise please continue.

vi /etc/environment

Change LANG from a UTF-8 setting:
LANG="en_US.UTF-8"

to a non UTF-8 setting:
LANG="en_US"

Save and exit the file as before. Note: you can run the command 'locale' to see the current settings. It is best to reboot after changing the /etc/environment file. Changes are not recognized until you at least log out, then back in.

We will use ntpdate to query a couple stratum 2 time servers in order to accurately set the system clock, then use a script (/etc/init.d/hwclock.sh) that will correct our hardware clock each time the system shuts down. We will later install the ntp daemon which will keep the clock accurate while the system is running. Hopefully at least one of these two servers will answer our request:
/etc/init.d/hwclock.sh reload

If this process hangs and you get a time out error, it's possible you have a bios incompatibility with the hwclock software. This is most common on some Dell machines. If and only if you have a problem here, perform this next step:
sed -i 's/HWCLOCKPARS=/HWCLOCKPARS="--directisa"/' /etc/init.d/hwclock.sh

Continue on:
ntpdate clock.fmt.he.net
ntpdate ntp1.tummy.com
/etc/init.d/hwclock.sh reload


If and only if you upgraded from sarge and do not have the hwclock.sh script:
hwclock --systohc


If you made changes to any of the above files:
reboot
[Ctrl]+d


[Ctrl]+d works the same as 'logout' or 'exit'
FYI, to power down the system, the command is:   shutdown -h now

******************************************************

Change apt-get settings:

Index
******************************************************
In Red Hat you would use "yum update" to get updates to installed packages. Red Hat automatically updates the local database of available packages before it updates packages to the newest version. In Debian, you use   apt-get update   to update the local database of available packages followed by   apt-get upgrade,   to install the latest version of any and all packages it found on our system. This is fine when we are using the 'stable' version of Debian. If you install 'testing' and 'unstable' versions of some (or all) software, this could spell disaster if we allow newer packages to be installed indiscriminately. This could make stuff stop working. Fortunately there is something called "Apt-Pinning" that enables us to prioritize the order of 'stable', 'testing', and 'unstable' software sources. This file has to be created by us. The most succinct explanation of this can be found at http://jaqque.sbih.org/kplug/apt-pinning.html. If you ever use "apt-get upgrade", I strongly recommend using   apt-get -s upgrade  to "simulate" the upgrade process before you actually upgrade. Make a mental note of this: if you were to have 'testing' software configured as your top priority, and you were to run 'apt-get upgrade', then many of your programs will be installed from the 'testing' group of packages. Once this happens, those packages will continue to update from the 'testing' branch even if you change your top priority to 'stable'. This action cannot be undone gracefully. Note that you can prevent any package you want from upgrading by placing the package on hold.
I use   echo "packagename hold" | dpkg --set-selections  to place package 'packagename' on hold and    echo "packagename install" | dpkg --set-selections  to allow it to upgrade.

This next file is critical to the way our system functions. I suggest you read the notes above before you continue. Note that since we installed etch (stable), the default priority for etch is 500 (the default Pin Priority for the stable release).
vi /etc/apt/preferences

Enter this text in the file ("i" to insert) EXACTLY as shown.
Yes, you can select the text with your mouse, hit [Ctrl]+c , and then right-click in the vi editor window.

Package: *
Pin: release a=unstable
Pin-Priority: 400

Package: *
Pin: release a=testing
Pin-Priority: 450

Exit the file with [Esc] : wq  as usual.

I recommend you use   apt-get -s install [package]   before you install any package. It lets you "simulate" what would happen. You will find that   apt-cache policy [package]  is also helpful. If you want a package that is an 'unstable' version (or any version that is not top priority), you would have to specifically request the 'unstable' version or change the priority before you install it (unless the only version is 'unstable' or your current version is 'unstable'). For example   apt-get -t unstable install [package] will install the package and also satisfy dependencies from 'unstable'. If you use   apt-get install [package]/unstable   then apt will try to meet any dependencies from stable. If you use tools like tasksel, you may have to temporarily change the priority prior to installing a new set of packages. The most stable situation is to only upgrade to new packages if a security flaw is found and make sure you have the ability to completely restore the hard drive if upgrades don't go well. So I don't frighten you too much, the Debian package maintainers are amazing, so apt-get usually works very well.

Use   apt-cache   to search the local database for available packages.
apt-cache search [search terms]   will find packages that sound like what you want and:
apt-cache show [packagename]   will return more details on a particular package.
apt-cache showpkg [packagename]   will return more details on a particular package.
apt-cache policy [packagename]   will return which versions are available along with the priority of each version.
apt-setup   will enable you to change mirrors. The alternative is to edit   /etc/apt/sources.list   manually (which I prefer).
apt-get clean clears the local repository of all retrieved package files.
apt-get autoclean clears the local repository of retrieved package files of programs that are no longer installed.
dpkg -l [packagename] will list the version and a short description of the package we have installed.

You can also search for packages at http://www.debian.org/distrib/packages or http://packages.debian.org. At a later time you can study these great instructions for searching your local package database: http://newbiedoc.sourceforge.net/tutorials/apt-get-intro/info.html.en Also grab http://www.oreilly.com/catalog/linuxnut4/chapter/ch05.pdf for later review.

We are going to add 'unstable' and 'testing' sources to our list of available Debian packages.
cp /etc/apt/sources.list /etc/apt/sources.backup

This creates a backup file. Then:

vi /etc/apt/sources.list
At this point, the contents of the file may look something like this:
#
# deb cdrom:[Debian GNU/Linux 4.0 r0 _Etch_ - Official i386 ]/ etch contrib main

deb cdrom:[Debian GNU/Linux 4.0 r0 _Etch_ - Official i386 ]/ etch contrib main

deb http://mirrors.kernel.org/debian/ etch main
deb-src http://mirrors.kernel.org/debian/ etch main

deb http://security.debian.org/ etch/updates main contrib
deb-src http://security.debian.org/ etch/updates main contrib

We need to modify this file so the result will look something like this:
(with only the http server unique to your particular system)

deb http://mirrors.kernel.org/debian/ etch main contrib non-free
deb-src http://mirrors.kernel.org/debian/ etch main

deb http://security.debian.org/ etch/updates main contrib
deb-src http://security.debian.org/ etch/updates main contrib

deb http://mirrors.kernel.org/debian/ unstable main contrib non-free
deb-src http://mirrors.kernel.org/debian/ unstable main

deb http://mirrors.kernel.org/debian/ testing main contrib non-free
deb-src http://mirrors.kernel.org/debian/ testing main

deb http://volatile.debian.net/debian-volatile etch/volatile main

Note what I have done here. Any lines that use the cdrom have been erased. ([up-arrow] to the top of the file and hold down the [Delete] key.)
The 2 'unstable' lines and the 2 'testing' lines have been copied from the top 2 'etch' lines, and then modified slightly as indicated.
The words "contrib non-free" have been added to 3 of the lines.
An etch 'Volatile' source has been added.
You are welcome to simply copy and paste what I have listed above.
Save and exit the file.
Here's a hint on how to quickly make a copy of the first 2 lines:
Enter "i" to get into write mode, highlight the 2 lines with your mouse then right click your mouse in the PuTTY window.

Because we are using a number of sources, it may be necessary to increase the apt cache limit:
echo 'APT::Cache-Limit "25165824";' >> /etc/apt/apt.conf


I also suggest adding gnupg keys for a few of the apt sources to apt. Note that if you are unable to retrieve keys from subkeys.pgp.net it might be an indication of some sort of firewall or proxy issue. If that is the case, you may end up having problems with other programs such as the DCC client::
gpg --keyserver subkeys.pgp.net --recv-key BBE55AB3
gpg --armor --export BBE55AB3 | apt-key add -
gpg --keyserver subkeys.pgp.net --recv-key 6070D3A1
gpg --armor --export 6070D3A1 | apt-key add -
gpg --keyserver subkeys.pgp.net --recv-key 16BA136C
gpg --armor --export 16BA136C | apt-key add -
gpg --keyserver subkeys.pgp.net --recv-key 276981F4
gpg --armor --export 276981F4 | apt-key add -



You must run apt-get update next.
apt-get update

If you have any problems, please check for errors in your sources.list file and run apt-get update again.
If you are using a multi-processor machine, then use a multi-processor kernel!
To locate available smp kernels for etch, you could run:

apt-cache search linux-image | grep smp | grep linux-image

If you are running a 2.6.18 (etch) kernel and have a dual core Intel system you could for example use the 'linux-image-2.6-686-smp' kernel. You would pick the kernel that most closely matches your system (and your current kernel). To install it, you would simply run:
apt-get install linux-image-2.6-686-smp

If you were to install a new kernel, please  reboot  afterwards.

Earlier I mentioned an errata dealing with tcp_window_scaling. You may want to consider what may happen (large files fail to transfer between systems) when there is a buggy router between you and someone else, and may wish to make this change to the system (you decide):
echo "net.ipv4.tcp_wmem = 4096 65536 65536" >>/etc/sysctl.conf
echo "net.ipv4.tcp_rmem = 4096 65536 65536" >>/etc/sysctl.conf
sysctl -p


I am going to assume this may slow down communications between systems under certain circumstances. Here is another setting I have not tried: http://en.wikipedia.org/wiki/TCP_window_scale_option.

******************************************************

Navigating the system:

Index
******************************************************
A quick word about   less.   less   is a great file and directory viewer.
You can [page-up] and [page-down] and search for text in the same manner you search for text using vi.
Use a lower case "q" to exit   less.
To view a file using   less:
less /path/file
To view directory contents, pipe it through   less:
ls -l | less     (current directory, or)
ls -l /path/directory | less

I also like this one:
history | less
then enter an upper case G to go to the bottom of the display.
It displays the commands you have entered previously. Use q to quit. You can even search the same way you do with vi.

I don't mean to break your concentration, but there is another cool tool called locate. locate   allows you to search a database of every file name on the system. It's kind of like Windows Find. You first have to build the database with the updatedb   command, and then you can search through it.
Try this: we are going to use   locate   and   less together:
updatedb
locate kmap | less
What you are looking at is every keymap file on the system along with any file name that has the string "kmap" in it.
Play with it; then "q" to exit less
Now we are going to do something cool.
Take your mouse and highlight any directory you see above, only highlight the directory and not past it.
For example:   /usr/share/keymaps/i386/qwerty/
Now right click your mouse anywhere on the screen. You will notice the text has been pasted to the command line.
Now [left-arrow] over to the beginning of the line (or hit [Ctrl]+a) and type in:
cd
Put a space after cd and hit [return]. We just saved ourselves having to type the entire path name just in order to change to that directory. I like that.
OK, simply enter cd to get back home.

Sorry for the diversion.

******************************************************

Create Firewall Rules:

Index
******************************************************
I like to set up a firewall on the boxes I biuld. This is a subject that could (and does) fill volumes. We are going to use something quick and simple that will give us a basic firewall. Something is better than nothing, and we just don't have time to read volumes on the subject right now.

I worked for a couple days trying to figure out what iptables was all about. I tried using tools like lokkit and shorewall and others, only to get frustrated and confused because I kept getting errors and the firewall simply would not work. My best guess is iptables did not like any rules file it did not create itself. Lokkit was a snap in Red Hat, and a nightmare in Debian. That's pretty much how this whole experience went. But I'm learning a LOT more about GNU/Linux by working with Debian. After day 2 it dawned on me iptables is somewhat like Cisco access lists (which I am a little familiar with).

I am going to give you a set of commands below that I want you to paste into the command line, in the correct order. You MUST change the IP addresses to fit your needs, if you have not already done so. The line with '--dport 22' on it is SSH and the network address to the left needs to be the network that both your computer and the spamfilter computer are on. You could also limit access to a single computer (yours, of course) by using     your_ipaddress_goes_here/32.   This is a security measure. If you do that part wrong, it will lock you out. The lines with '--sport 53' on them are for access to DNS servers. BTW, all you have to do to change your DNS servers is change the entries in /etc/resolv.conf.

If you would like to add more rules in the future or make modifications, simply copy and paste these lines into a text editor like notepad, make the changes you would like, and then copy and paste them to a command prompt in your PuTTY window. You can copy and paste all the lines at once. The first line deletes all the entries that were in the rule-set previously and the next to the last line saves the new rule set. The last line shows how one would load a rules file into iptables. Keep a copy of the text file on your computer and call it firewall-rules.txt. I learned to never edit the /etc/firewall-rules file directly on the spamfilter computer. It looks like iptables will reject the file if anything other than itself has modified it.

DO NOT USE AS IS, CHANGE NETWORK ADDRESS FIRST IF YOU HAVE NOT ALREADY DONE SO:
You can copy and paste this whole section to the command prompt:
iptables -F
iptables -N FIREWALL
iptables -F FIREWALL
iptables -A INPUT -j FIREWALL
iptables -A FORWARD -j FIREWALL
iptables -A FIREWALL -p tcp -m tcp --dport 25 --syn -j ACCEPT
iptables -A FIREWALL -p tcp -m tcp -s 222.222.222.222/24 --dport 22 --syn -j ACCEPT
iptables -A FIREWALL -i lo -j ACCEPT
iptables -A FIREWALL -p udp -m udp --sport 53 -j ACCEPT
iptables -A FIREWALL -p tcp -m tcp --sport 53 -j ACCEPT
iptables -A FIREWALL -p udp -m udp --dport 123 -j ACCEPT
iptables -A FIREWALL -p udp -m udp --sport 6277 -j ACCEPT
iptables -A FIREWALL -p udp -m udp --sport 24441 -j ACCEPT
iptables -A FIREWALL -p tcp -m tcp --syn -j REJECT
iptables -A FIREWALL -p udp -m udp -j REJECT
iptables-save > /etc/firewall-rules
iptables-restore < /etc/firewall-rules


Now run:
iptables -L

To list the rule set. This is informational only.

We have written the firewall rules to a file on the spamfilter computer and then used iptables to load the rules, but iptables starts with an empty rule set each time the computer restarts. The rule set we saved to /etc/firewall-rules must be loaded into iptables every time the system starts up.

We are going to insert the command to configure iptables into a file that starts up the network interfaces when the system boots up:
vi /etc/network/interfaces

And insert the following text (remember, it's "i" to insert) in the blank line just below "iface lo inet loopback":
pre-up iptables-restore < /etc/firewall-rules

Save and exit the file as usual with [Esc] : wq
From now on I will assume you know how to edit, save, and exit files using vi.
If not stated, it will be implied that after editing a file, you need to save and exit it,
or if necessary, discard changes and start over.
Please don't think this is where you would stick any old command you would like. This is not the place, and not the way, to do so. That's a whole 'nuther subject. This file is the right place (along with /etc/resolv.conf) to change network settings however.

That's all there is to it. You have just used what I believe is the fewest possible steps to create a simple functional personal firewall for this machine. I will admit that it should have been a lot easier by utilizing one of the firewall tools, but it just didn't work out.

At this point our firewall allows external users to connect to SSH and Mail. It also allows replies from Pyzor, DCC, DNS servers and NTP servers. It blocks (I hope) everything else except any sessions that originate from us. This allows us to connect to the outside world. This box should be behind another firewall at any rate. If so, that firewall/screening router will need to be configured to allow tcp port 25 traffic to this machine, but only after this box is fully functional. If you have things locked down really tight; take a look at http://flakshack.com/anti-spam/wiki/index.php?page=Provide+firewall+access for some ideas. Keep in mind we also need udp port 24441 for Pyzor and access to external DNS servers. As far as DCC, Razor and Pyzor go, try them before you start messing with your Internet firewall. I have my spamfilter behind a screening router, a hardware firewall, and software NAT box firewall and none of them required reconfiguration for these programs to work. Port 25 SMTP will probably need to be opened however.

If you have not done so, reboot again and run
iptables -L  to verify the firewall loaded during start up.

If you have problems, enter the command  iptables -F   from the console to clear out iptables. This will allow you another shot at it.

******************************************************

Disable Unnecessary Daemons:

Index
******************************************************
We are now going to remove some services (daemons) that start up at boot time. I only want you to remove the services I have listed below, no more than that. You could (and probably would) end up with an unusable system if you disabled more than this. Our basic system does not start up many services anyway but "you can't hack a service that isn't running". The only secure system is a system that doesn't exist.

Below is a list of commands I found useful to determine what services were running.
Run them one at a time if you care to.
top
ps afx
ps afxl
ps -A
ls -F /etc/rc2.d
lsof -i | grep LISTEN
lsof -P | grep LISTEN
netstat -pn -l -A inet
netstat -pn -l inet

These are from http://linuxgazette.net/issue89/gonzales.html#4

I also liked the lsconfig script I found here:
http://www.shallowsky.com/software/scripts/lsconfig
Save it as /usr/bin/lsconfig and make it executable.
Like this:
cd /usr/bin
wget http://www200.pair.com/mecham/debian/lsconfig
chmod +x /usr/bin/lsconfig
lsconfig

If you run lsconfig, the stuff just scrolls by on the screen. You can choose "Copy all to Clipboard" from the drop down menu of the PuTTy window. Click on the two little computers in the upper left-hand corner of the PuTTY window to access the menu. Then open a spreadsheet and paste it into it. Play with it from there.

We need to make a backup of the init scripts in /etc/init.d because after we remove some services, the system may delete the scripts.
cp -r /etc/init.d /etc/init.d-original


These commands assume you are not hooking up a printer to this machine and you are not using NFS (Network File System). Feel free to copy and paste these next two boxes in their entirety.
/etc/init.d/lpd stop
update-rc.d -f lpd remove
/etc/init.d/nfs-common stop
update-rc.d -f nfs-common remove
/etc/init.d/portmap stop
update-rc.d -f portmap remove
/etc/init.d/exim4 stop
update-rc.d -f exim4 remove


The inetd service (InterNET Daemon) starts multiple services that can be enabled or disabled individually.
update-inetd --disable time
update-inetd --disable daytime
update-inetd --disable echo
update-inetd --disable chargen
update-inetd --disable ident
update-inetd --disable discard


Check that we got everything:
lsof -i | grep LISTEN

The only daemon you should see is at this point is   *:ssh

If there are other programs shown, try rebooting and test again.

If you would like to get any of these services back, we can reverse the events. For example, to enable 'ident':
update-inetd --enable ident

For example, to re-enable the nfs-common service, and start it up right now:
update-rc.d nfs-common defaults
/etc/init.d/nfs-common start


If you get an error that the file does not exist, first restore it from the backup we made, and then try again:
cp -i /etc/init.d-original/nfs-common /etc/init.d
update-rc.d nfs-common defaults
/etc/init.d/nfs-common start


This is an example only, you probably don't want to enable NFS.

We have just made our machine more secure than when we started. I will talk about additional security measures at the end of this document, but we want to get this thing up and running first! We want to see this puppy actually do something! You used a few commands above to help you see what services were running before we made changes. Run them again, if you like, to see the effect of disabling them.

******************************************************

Configure the NTP daemon:

Index
******************************************************
Install the program:
apt-get install ntp

We actually may not need to configure the ntp daemon (ntpd). We installed ntp which does a good job of setting everything up for us. It is set up to use a different time server each time the daemon starts up (http://www.pool.ntp.org/). It configures our machine as an ntp client. If you have a favorite ntp server that you wish to use you can edit   /etc/ntp.conf   and insert it per the example in the file. NTP is a flexible and complex system so I leave it up to you to research it further if you care to. If you care to choose your own servers from the list of Public NTP Secondary (stratum 2) Time Servers at http://support.ntp.org/bin/view/Servers/StratumTwoTimeServers we can use the little ntpdate program to quickly test them prior to insertion in /etc/ntp.conf:

For example:

/etc/init.d/ntp stop
ntpdate clock.fmt.he.net
ntpdate ntp1.tummy.com
/etc/init.d/ntp start

By the way, the command to modify the date and time is    date   and to change the time zone it's    tzconfig

Since we are using the etch CD, our default system editor will be nano, and not vim. We soon need to edit a system file called crontab but we don't want to have to learn another new editor so we will change our default system editor:
vi /root/.profile

and just below the line "fi" insert this entry:
export EDITOR=/usr/bin/vim.basic

Save and exit the file, then logout of PuTTY ([Ctrl]+d), then connect back in.

******************************************************

Installing Programs:

Index
******************************************************
We need to install a number of additional programs. Go ahead and select ALL the text in the box below with your mouse, then use [Ctrl]+c to copy it to the clipboard, then right-click the PuTTY window, then hit [enter] to issue the command. I suggest you select from right to left (bottom to top). Going the other way always wants to select one extra space character which can be a problem with apt-get commands.
apt-get install arc arj autoconf automake1.7 bzip2 cabextract db4.4-util libarchive-tar-perl libarchive-zip-perl libauthen-sasl-perl libberkeleydb-perl libconvert-binhex-perl libconvert-tnef-perl libconvert-uulib-perl libdb4.4-dev libdbd-mysql-perl libdbi-perl libdigest-hmac-perl libdigest-sha1-perl libhtml-format-perl libhtml-parser-perl libhtml-tagset-perl libhtml-tree-perl libio-multiplex-perl libio-socket-ssl-perl libio-string-perl unrar arj

And there are more:
apt-get install libio-stringy-perl libio-zlib-perl libldap2 libmail-spf-query-perl libmailtools-perl libmime-perl libnet-dns-perl libnet-ldap-perl libnet-ph-perl libnet-server-perl libnet-snpp-perl libnet-telnet-perl libsocket6-perl libtimedate-perl libtool libunix-syslog-perl liburi-perl libwww-perl lynx lzop make ncftp nomarch pax perl-doc rblcheck unzip zip zlib1g-dev pyzor razor libcompress-zlib-perl psmisc re2c curl

apt-get install lha

If this fails you are probably using the amd64 kernel, if (and only if) lha cannot be installed, you can try a Java based lha if you like (but you will also install a bunch of Java stuff):
apt-get install jlha-utils


For lha license information see http://lists.debian.org/debian-devel/1999/11/msg00549.html and for rar (unrar) see http://www.rarsoft.com/index.htm

This is a new system, so let's make sure everything is current.
First, run a simulation:
apt-get -s upgrade

Then if everything is as you might expect:
apt-get upgrade

Upgrading certain programs may bring up dialog boxes requiring you to respond to configuration questions. Typically, the default answers are OK.

If the kernel is upgraded, once the upgrade process is complete, you must:
reboot

We are using apt-get to download and install most of our core programs. Note that when we install Postfix, apt-get is smart enough to remove exim4 (because it conflicts with Postfix). This document is based of the following versions of these programs: postfix 2.3.x    spamassassin 3.1.x    amavisd-new 2.5.4. The instructions may differ significantly if newer (or older) versions are installed. Please run:
apt-cache policy postfix spamassassin


This will give output similar to the following:
postfix:
  Installed: (none)
  Candidate: 2.3.8-2+b1
  Version table:
     2.4.6-1 0
        400 http://mirrors.kernel.org unstable/main Packages
        450 http://mirrors.kernel.org testing/main Packages
     2.3.8-2+b1 0
        500 http://mirrors.kernel.org etch/main Packages
spamassassin:
  Installed: (none)
  Candidate: 3.1.7-2
  Version table:
     3.2.3-1 0
        400 http://mirrors.kernel.org unstable/main Packages
     3.2.1-1 0
        450 http://mirrors.kernel.org testing/main Packages
     3.1.7-2 0
        500 http://mirrors.kernel.org etch/main Packages
This tells us that the etch versions of Postfix and SpamAssassin will be installed. If we wanted to install the testing version of a program (for example), we would have to override the choices, e.g.   apt-get install [packagename]/testing,   or if necessary   apt-get -t testing install [packagename].   Note that another option is to momentarily make testing the highest priority in /etc/apt/preferences, then override what will be installed, e.g.   apt-get install [packagename]/testing. Read this. Remember that it's a good idea to simulate an installation first (using the -s switch). If you are interested in installing a newer (3.2.x) version of SpamAssassin, you could read my notes from one of my other documents: http://www200.pair.com/mecham/spam/virtualp2.html#spa. There is a Debian version of amavisd-new available, but are NOT going to install it. The configuration files for newer Debian (testing/unstable) versions of amavisd-new are not consistent with the typical way amavisd-new is configured. Instead of one configuration file, the newer Debian versions split the configuration files into half a dozen files in a couple different directories. We will instead install amavisd-new from the original author. So with this in mind:
Read instructions above before you proceed.
apt-get install spamassassin

If you install 3.1.7 and want to prevent upgrades to 3.2.x (via etch volatile - which we configure later), you will need to place the package on hold:
echo "spamassassin hold" | dpkg --set-selections


apt-get install postfix postfix-pcre postfix-mysql postfix-ldap


Debconf will pop up a Postfix configuration screen.
For [General type of configuration?] select:
No configuration

Don't worry, we will configure Postfix in a few minutes.

If (and only if) you already have amavisd-new installed, you need to remove it (this will not remove your configuration files which is a good thing). First make sure amavisd-new is the only thing that will be removed by 'simulating' the removal:
apt-get -s remove amavisd-new

If it is, then remove it:
apt-get remove amavisd-new

If it is not, then you must make a note of any and all programs that will be removed, because you will have to reinstall them. Good luck with all that. ;)

Here are all the steps needed to install amavisd-new. Some of the files it tries to delete or copy may not be on your system but there is no need to panic if it fails to find them. The last few dpkg-statoverride commands will also fail if you have ever installed Debian amavisd-new - but this is not an issue either. We are going to place files in the same place the Debian version of amavisd-new would have.
There may be complaints that some things do not exist and other things already exist. This should not be a problem.

adduser --group --system --home /var/lib/amavis --shell /bin/sh amavis
mkdir /var/run/amavis
chown amavis:amavis /var/run/amavis
mkdir /etc/amavis
mkdir /etc/amavis/en_US
mkdir /var/lib/amavis/tmp
mkdir /var/lib/amavis/db
mkdir /var/lib/amavis/var
mkdir /var/lib/amavis/virusmails
chown -R amavis:amavis /var/lib/amavis
chmod -R 750 /var/lib/amavis
cd /etc/amavis
wget http://www200.pair.com/mecham/amavisd/2.5.4/amavisd.conf

Did you get that wget download OK? If you did, then continue on. If not, then you won't be able to get other downloads from me, so you have a major problem.

wget http://www200.pair.com/mecham/amavisd/2.5.4/amavisd.conf-sample
ln -s /etc/amavis/amavisd.conf /etc/amavisd.conf

cp -r /etc/amavis/en_US /etc/amavis/en_US-backup
cd /etc/amavis/en_US
rm charset
rm template-dsn.txt
rm template-spam-admin.txt
rm template-spam-sender.txt
rm template-virus-admin.txt
rm template-virus-recipient.txt
rm template-virus-sender.txt
wget http://www200.pair.com/mecham/amavisd/2.5.4/en_US/charset
wget http://www200.pair.com/mecham/amavisd/2.5.4/en_US/template-dsn.txt
wget http://www200.pair.com/mecham/amavisd/2.5.4/en_US/template-spam-admin.txt
wget http://www200.pair.com/mecham/amavisd/2.5.4/en_US/template-spam-sender.txt
wget http://www200.pair.com/mecham/amavisd/2.5.4/en_US/template-virus-admin.txt
wget http://www200.pair.com/mecham/amavisd/2.5.4/en_US/template-virus-recipient.txt
wget http://www200.pair.com/mecham/amavisd/2.5.4/en_US/template-virus-sender.txt

cd /usr/local/src
wget http://www.ijs.si/software/amavisd/amavisd-new-2.5.4.tar.gz
tar xzvf amavisd-new-2.5.4.tar.gz
cd amavisd-new-2.5.4
test -e /usr/sbin/amavisd-new && cp /usr/sbin/amavisd-new /usr/sbin/amavisd-new-debian
cp amavisd amavisd-new

cp amavisd-new /usr/sbin/amavisd-new
cp amavisd-new /usr/sbin/amavisd-new-2.5.4
cd /etc/init.d
wget http://www200.pair.com/mecham/debian/amavis-init-20030616
mv amavis-init-20030616 amavis
chmod +x amavis
update-rc.d amavis defaults
cd /etc/cron.daily
wget http://www200.pair.com/mecham/crondaily/amavisd-new.txt
mv amavisd-new.txt amavisd-new
chmod +x amavisd-new
cd /etc/cron.d
wget http://www200.pair.com/mecham/crond/amavisd-new.txt
mv amavisd-new.txt amavisd-new
dpkg-statoverride --add amavis amavis 755 /var/lib/amavis
dpkg-statoverride --add amavis amavis 755 /var/lib/amavis/virusmails
dpkg-statoverride --add amavis amavis 755 /var/run/amavis



******************************************************

Postfix Configuration Part 1:

Index
******************************************************
We need some sample files from the Postfix source code.
cd /usr/local/src

Change these next lines to match the (author's) version of Postfix you have (hint: dpkg -l postfix ):
wget http://ftp.debian.org/debian/pool/main/p/postfix/postfix_2.3.8.orig.tar.gz
tar xzvf postfix_2.3.8.orig.tar.gz


We always place our source code in /usr/local/src.

List the contents of this directory:
ls -l


We have created a new subdirectory and unpacked the source code into it. Mine is called postfix-2.3.8. We don't need to keep the compressed file. Make sure you are still in the /usr/local/src directory, then remove the compressed file(s) with the command:
rm postfix_2*
rm amavisd-new-2.5.4.tar.gz
ls -l



When we downloaded our Postfix source code, a number of sample files were included. We want to make use of those sample files so we will copy them to the postfix directory.
The second line below may need to be edited if your version of the Postfix source code is different than mine.
MAKE SURE you answer "n" to "overwrite?" Do each section separately.


cp -i /usr/share/postfix/main.cf.debian /etc/postfix/main.cf

cp -i /usr/local/src/postfix-2.3.8/conf/* /etc/postfix

cp -i /etc/postfix/header_checks /etc/postfix/body_checks

cp -i /etc/postfix/access /etc/postfix/sender_access


******************************************************

Edit master.cf:

Index
******************************************************
Read this before you complete this section.
I have done the work of configuring master.cf for you and you may simply download the file from me. If you wish to use my file, follow the first 4 steps below.

The master.cf we download here can be used with recent Postfix versions.

postfix stop
cd /etc/postfix
mv master.cf master.cf-original
wget http://www200.pair.com/mecham/debian-postfix-2.3-amavisd/master.cf

Note that wget will not normally overwrite an existing file, so we "moved" master.cf to another file first.
Now you can simply jump to Edit Main.cf:

If you wish to do the work yourself, continue on. Or, you may wish to simply read what changes I have made to master.cf.
postfix stop
vi /etc/postfix/master.cf

Next, we want to give Postfix some information it will need to talk to the amavisd-new program.
Add these lines near the bottom of master.cf. The "-o" is the lower case letter o, not zero. These settings are from http://www.ijs.si/software/amavisd/README.postfix. You can copy and paste this entire section once the cursor is in the correct position (see below) and you are in insert mode. Note: rather than using a right click of the mouse to paste into the editor, you can also use [Shift]+[Insert]:
smtp-amavis    unix    -    -    -    -    2    smtp
    -o smtp_data_done_timeout=1200
    -o smtp_send_xforward_command=yes
    -o disable_dns_lookups=yes

127.0.0.1:10025    inet    n    -    -    -    -    smtpd
    -o content_filter=
    -o smtpd_restriction_classes=
    -o smtpd_delay_reject=no
    -o smtpd_client_restrictions=permit_mynetworks,reject
    -o smtpd_helo_restrictions=
    -o smtpd_sender_restrictions=
    -o smtpd_recipient_restrictions=permit_mynetworks,reject
    -o smtpd_data_restrictions=reject_unauth_pipelining
    -o smtpd_end_of_data_restrictions=
    -o mynetworks=127.0.0.0/8
    -o smtpd_error_sleep_time=0
    -o smtpd_soft_error_limit=1001
    -o smtpd_hard_error_limit=1000
    -o smtpd_client_connection_count_limit=0
    -o smtpd_client_connection_rate_limit=0
    -o smtpd_milters=
    -o local_header_rewrite_clients=
    -o local_recipient_maps=
    -o relay_recipient_maps=
    -o receive_override_options=no_header_body_checks,no_unknown_recipient_checks

We also need to add two items below the 'pickup' service type. The 'pickup' service 'picks up' local mail (local meaning "on this machine") and delivers it. Later we will create a daily/weekly report that this box will mail to us and because the report will contain contents that will classify the report itself as spam, this is a way to bypass content filtering for mail generated by this machine.
Add this just below the 'pickup' service type:
    -o content_filter=
    -o receive_override_options=no_header_body_checks

When you are all done, the table and the lines right after it should end up looking like this:
# ==========================================================================
# service type  private unpriv  chroot  wakeup  maxproc command + args
#               (yes)   (yes)   (yes)   (never) (100)
# ==========================================================================
smtp      inet  n       -       -       -       -       smtpd
#  -o receive_override_options=no_address_mappings
#submission inet n       -       -       -       -       smtpd
#  -o smtpd_enforce_tls=yes
#  -o smtpd_sasl_auth_enable=yes
#  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
#smtps     inet  n       -       -       -       -       smtpd
#  -o smtpd_tls_wrappermode=yes
#  -o smtpd_sasl_auth_enable=yes
#  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
#628      inet  n       -       -       -       -       qmqpd
pickup    fifo  n       -       -       60      1       pickup
    -o content_filter=
    -o receive_override_options=no_header_body_checks
cleanup   unix  n       -       -       -       0       cleanup
qmgr      fifo  n       -       n       300     1       qmgr
#qmgr     fifo  n       -       -       300     1       oqmgr
tlsmgr    unix  -       -       -       1000?   1       tlsmgr
rewrite   unix  -       -       -       -       -       trivial-rewrite
bounce    unix  -       -       -       -       0       bounce
defer     unix  -       -       -       -       0       bounce
trace     unix  -       -       -       -       0       bounce
verify    unix  -       -       -       -       1       verify
flush     unix  n       -       -       1000?   0       flush
proxymap  unix  -       -       n       -       -       proxymap
smtp      unix  -       -       -       -       -       smtp
# When relaying mail as backup MX, disable fallback_relay to avoid MX loops
relay     unix  -       -       -       -       -       smtp
    -o fallback_relay=
#       -o smtp_helo_timeout=5 -o smtp_connect_timeout=5
showq     unix  n       -       -       -       -       showq
error     unix  -       -       -       -       -       error
discard   unix  -       -       -       -       -       discard
local     unix  -       n       n       -       -       local
virtual   unix  -       n       n       -       -       virtual
lmtp      unix  -       -       -       -       -       lmtp
anvil     unix  -       -       -       -       1       anvil
scache    unix  -       -       -       -       1       scache
#
smtp-amavis    unix    -    -    -    -    2    smtp
    -o smtp_data_done_timeout=1200
    -o smtp_send_xforward_command=yes
    -o disable_dns_lookups=yes

127.0.0.1:10025    inet    n    -    -    -    -    smtpd
    -o content_filter=
    -o smtpd_restriction_classes=
    -o smtpd_delay_reject=no
    -o smtpd_client_restrictions=permit_mynetworks,reject
    -o smtpd_helo_restrictions=
    -o smtpd_sender_restrictions=
    -o smtpd_recipient_restrictions=permit_mynetworks,reject
    -o smtpd_data_restrictions=reject_unauth_pipelining
    -o smtpd_end_of_data_restrictions=
    -o mynetworks=127.0.0.0/8
    -o smtpd_error_sleep_time=0
    -o smtpd_soft_error_limit=1001
    -o smtpd_hard_error_limit=1000
    -o smtpd_client_connection_count_limit=0
    -o smtpd_client_connection_rate_limit=0
    -o smtpd_milters=
    -o local_header_rewrite_clients=
    -o local_recipient_maps=
    -o relay_recipient_maps=
    -o receive_override_options=no_header_body_checks,no_unknown_recipient_checks

(Don't worry about the stuff below this part displayed above - you won't need to change any of those rows, and they are all listed as "pipe" in the last column.)

******************************************************

Edit main.cf:

Index
******************************************************
Our next friend is the file   /etc/postfix/main.cf   the main configuration file for Postfix. Following are suggested values to use in main.cf. These have been tested for this configuration and will work fine, but there are many judgment calls involved in this, and it is a good idea at some point to learn more about Postfix configuration on your own. You could first look at the sample Postfix main.cf file /usr/share/postfix/main.cf.dist   . There are comments describing some of the most common options. Refer also to the Postfix documents on your machine in the   /usr/local/src/postfix-2.3.8/README_FILES directory, or read the documentation on the Postfix web site http://www.postfix.org/documentation.html. I also recommend http://www.postfix-book.com/.

Since we are setting up our spamfilter to relay all of its mail to another server, we will be using what Postfix considers a "relay domain address class" which essentially means that we will use (change from the default value), out of the 300+ configurable parameters in Postfix, a small group of parameters that serves our purpose best. This address class is described here: http://www.postfix.org/ADDRESS_CLASS_README.html#relay_domain_class. We are also acting as a primary MX for another server so please read this appropriate section: http://www.postfix.org/STANDARD_CONFIGURATION_README.html#backup

It is common in Postfix to store items in lookup tables. We are going to use several hash tables to store data that Postfix will use. Once we have plain text data in these tables, we use the postmap command to create binary files (Berkeley DB format) that Postfix will ultimately use to retrieve the data. For example, if you have a file called "filename" and you "postmap filename", a new file is created "filename.db". When we reference the file as data type "hash:", Postfix will retrieve data from "filename.db", not "filename". There are more than a dozen other types of data files that Postfix can use to store data. Hash tables are an appropriate choice for several tables we will use, and pcre (Perl Compatible Regular Expressions) is appropriate for a couple tables we will use to hold content filtering data. In its simplest form a hash table is comprised of 2 pieces of data, a key and a value; typically referred to as the key/value pair. The key and the value are separated with whitespace (typically a space or tab). The data in a typical table that we use in Postfix would look something like:
user1@example.com OK
user2@example.com OK
user1@example2.com OK
Suggested reading: http://www.postfix.org/DATABASE_README.html

OK, lets get going. Note: in commands wherever quote marks " " are used, use them. Rather than editing main.cf directly (which you may nonetheless do, if you prefer) we'll use a handy tool that comes with Postfix, named "postconf". We will use the -e switch, which means to "edit" main.cf.

We simply need to make a correction to the default setting here:
postconf -e "alias_maps = hash:/etc/aliases"


Now we will create from the text version of the aliases file, the binary version that Postfix will actually use. We do not need to edit the aliases file at this time but it would be a good idea to do so simply to view the contents. You need to run newaliases now, and every time after you edit the aliases file. The newaliases command is just like postmap except that it's specific to the aliases file.
newaliases

You will see there is now an "aliases.db" file in /etc/. That is what Postfix reads. Now that you have a proper aliases file, it appears that because we are going to configure our system to relay all mail (no mail will be locally delivered), the aliases file will be ignored by Postfix. We instead will set up virtual_alias_maps that we can use for address rewriting should we need to. Other programs may read/write to the /etc/aliases file, so we do not remove it.

myorigin and mydomain The domain name that mail created on this machine appears to come from. For example, if one of our programs (cron for example) sends mail from "root" it will be sent from "root@example.com".
postconf -e "myorigin = example.com"
postconf -e "mydomain = example.com"
Obviously, in the above, and all the following commands, replace my example parameters, like "example.com", with your own specific values.

myhostname The fully-qualified domain name (FQDN) of the machine running the Postfix system.
postconf -e "myhostname = sfa.example.com"

mynetworks These are the machines I trust, and will relay mail for, to any destination. Generally, this is set to my LAN, or just one, or a few trusted internal mail servers. Along with "relay_domains", this is an important one to get right lest you run the possibility of becoming an "open relay". In other words, your box could accept and forward mail to domains for which it has no business doing so. Being an open relay is a serious issue, and can cause you to get blacklisted by various Internet anti-spam lists, among other problems. You can specify a single computer, multiple individual computers, or any computer on a specified network. You can also exclude certain hosts in your network by preceding the IP address with an exclamation point. Excluded addresses need to be listed before included addresses. If you are using a NAT router that substitutes the real client IP address with its own, then you must exclude the IP address of the NAT router from mynetworks. If you will be dealing with multiple internal mail servers, and/or want to allow several machines and/or subnets to relay through this server (careful!), just add them to this parameter in CIDR format, like this:
Please read important notes above.

postconf -e "mynetworks = 127.0.0.0/8, 222.222.222.222/24, 10.10.10.10/24"
The above will allow the machines on the networks 222.222.222.222/24, and 10.10.10.10/24 to relay smtp mail through this box. You could also specify a single computer's IP address. If you only know your dotted decimal netmask (i.e. 255.255.255.240) and need to convert it to CIDR format, try the http://www.wildpackets.com/products/free_utilities/ipsubnetcalc/overview. (Input an IP address on your network, select the subnet info tab, select your subnet mask, your network is Subnet ID/Mask Bits.) Or simply take a look at http://www.belchfire.net/webtools/cidr_conversion_table.html.

message_size_limit Maximum size email that Postfix will let in the "front door".
postconf -e "message_size_limit = 10485760"

The above allows email up to 10MB; the value is in bytes (10*1024*1024). If you increase this consider that mail larger than 10MB may possibly get bypassed by ClamAV (but we can increase ArchiveMaxFileSize in /etc/clamav/clamd.conf to compensate).

local_transport Give an error message for local delivery attempts.
postconf -e "local_transport = error:no local mail delivery"


mydestination An empty mydestination tells Postfix this machine is not the final destination.
postconf -e "mydestination = "


local_recipient_maps An empty local_recipient_maps tells Postfix there are no local mailboxes.
postconf -e "local_recipient_maps = "


virtual_alias_maps Our spamfilter must be able to receive mail for postmaster@[111.111.111.111]. Reportedly, some things actually expect this ability to exist. We will also allow mail to abuse@[111.111.111.111]. Since we do not allow local mail delivery, mail addressed to our spamfilter IP address will get rejected with an error message. Setting up virtual_alias_maps allows email to these two accounts to be forwarded to an inside address. Make sure your Exchange server is set up to receive messages addressed to "postmaster" and "abuse".
Set up a reference to the virtual file:
postconf -e "virtual_alias_maps = hash:/etc/postfix/virtual"

Then edit the virtual file:
vi /etc/postfix/virtual

and add postmaster and admin in the format:
postmaster postmaster@example.com
abuse abuse@example.com

Save and exit the file, then create the binary file that Postfix will use:
postmap /etc/postfix/virtual


relayhost Generally speaking, if this machine is on an internal network (with no public IP address), you may need to configure 'relayhost'. If it is on the Internet serving as a gateway server, you would only configure 'relayhost' if you must relay your mail through some other server (like your ISP's), otherwise you would not. The relayhost is the email server you wish to use to send outbound email. The outbound email I'm talking about is the non-local mail, mail bound for domains other than ours, not the normal email that comes from outside the system and is bound for your internal mailboxes (we use /etc/postfix/transport to route those). At this time you are using a machine other than this one to send mail out to the Internet so you could place the IP address of that machine here (the brackets must be there). If preferred, you can use a host name instead of an IP address (keep the brackets, i.e. [gateway.example.com]). If this is blank, or not configured, then Postfix will use DNS to deliver outbound mail (which is the ideal configuration). It is best to not use relayhost, but if you do not, you should first have your reverse DNS record in place and of course your "A" record and "MX" record so other servers on the Internet will accept mail from this machine at this IP address. If these are not yet in place, it may be useful to temporarily configure relayhost. If you point relayhost to the Exchange server, the Exchange server (or other SMTP server) must be configured to allow our spamfilter to relay mail through it http://www.msexchange.org/pages/article.asp?id=54. You need this so bounces have a way out of the network.
Read the notes above before you enter this: