Secure email servers from scratch with FreeBSD 6.1 (part 1)

Build a secure email server with FreeBSD, Postifx, ClamAV, Spamassasin, and MySQL

Download the whole article as PDF

Short URL: http://fsmsh.com/1376

Write a full post in response to this!


FreeBSD—it’s the other white meat. Perhaps you are a long time GNU/Linux user and have been curious about experimenting with the other half of Open Source, the BSD class of operating systems. The 6.1 release is just around the corner, the first batch of RCs (release candidates) are already hitting the FreeBSD mirrors and by the time this article hits the press, 6.1 will probably have been released. The time has come for the adventurous to forgo their penguins and get down with the beastie.

Introduction

This article will cover the steps involved in setting up a highly secure email server using FreeBSD, Postfix, Cyrus-imap (SSL), Squirrelmail (webmail), ClamAV and Spamassain. The mail host will be able to host virtual domains, and virtual users backed by a MySQL database.

All required information will be covered from installing and hardening FreeBSD with ipfw, installing packages from the venerable ports system, understanding the role DNS plays in email to securing Postfix and configuring ClamAV and Spamassain for anti-virus and spam filtering.

This is the first part of a two part series. This first part will cover the history and origins of FreeBSD, installation and configuration of the base system, updating and installing packages from ports, and securing the system with ipfw2. The second part will cover configuring Postfix, MySQL, and Cyrus-imap over SSL, configuring ClamAV and Spamassain for anti-virus and spam filtering, and Squirrelmail over Apache SSL for secure web mail when you are away from your computer.

FreeBSD is used by Yahoo, Coyote Point, and countless others

Email server terminology

When diving into the world of managing your own email server, it’s easy to get lost on a sea of acronyms such as “MTA”, “MUA”, and “MX” record.

Mail Transfer Agent (MTA): this is the email “server”. Postfix (discussed in the second article) is an MTA, other (in)famous MTAs are Sendmail and qmail. The MTA works behind the scenes accepting mail for users it is in charge of, and forwarding mail to other MTAs.

Mail User Agent (MUA): this is the client that users typically interact with. Mozilla-Thunderbird and Microsoft Outlook are MUAs. Mail User Agents send emails to MTAs which then either deliver them to users, or another MTA.

Mail exchanger (MX): is the terminology used by DNS, the system that resolves IP numbers to human readable host names. In the DNS configuration there is a special entry for email servers that sets the priority of the email, which is used when there are multiple email servers and one stops responding, and the name of the email server itself.

The history of FreeBSD

The origins of FreeBSD go back to the University of California Berkeley during the late ’70s, and the suffix “BSD” is an acronym for “Berkeley Software Distribution”. Initially FreeBSD started as an outgrowth of the 386BSD project, also known as JOLIX. The 386BSD project itself was a patch set of the 4.3BSD, from which the University of California Berkeley had withheld a large amount of code as part of their agreement with Novell.

In the early ’90s Novell, which had purchased the IP rights to AT&T’s UNIX System, sued the University of California for patent infringement. It was around this time that Linus Torvalds released the initial Linux kernel, and the rest was history. Novell and The University of California eventually settled. It was agreed that certain parts of the code base, then called 4.4BSD, were encumbered. The University of California removed the tainted code and released the 4.4BSD-Lite operating system; however large parts of it were removed, and a bootable, working version for intel processors was not available.

In 1993, development of 386BSD seemed to have stagnated, and there was a growing back log of patches that Lynne and William Jolitz, the original creators of the project were not merging into the main code base. Eventually, a group of developers including Jordan Hubbard, decided that the project was worth continuing on its own, even without the support of Jolitz. In December of 1993 the FreeBSD project released its 1.0 version. The name “FreeBSD” was coined by David Greenman. This initial release was still based on the encumbered 4.4BSD-Net/2 distribution; it wasn’t until FreeBSD 2.0 that FreeBSD was free of patented intellectual property. The rest is history.

While Linux took the (free software) world by storm, FreeBSD was still recovering lost mindshare from the doubt and uncertainty cast by the Novell law suit

Bill Joy, BSD, vi, and Sun

An interesting side note is that Bill Joy, of Sun Microsystems fame, was one of the original creators of BSD software. During his time at the University of California Berkeley, he also wrote the original, “vi” editor. Sun Microsystems earlier offering “SunOS” was based on BSD code from the early ’80s until the early ’90s when Sun released SunOS 4.0 based on AT&T’s SysV code. Sun attempted to clarify the change by marketing “Solaris” instead of “SunOS” although “SunOS” referred to as the core operating system, while “Solaris” is considered an operating environment; thus Solaris 10 is SunOS 5.10.

FreeBSD sports a new multi-threaded file system that increases performance on systems such as email and database servers

What’s new

The 6.0 branch represents a mixture of stabilizing features introduced in the 5.x branch and some new features. The 5.x branch introduced a new scheduler called “ULE” around the same time the linux 2.6 kernel introduced the new anticipatory scheduler. A very new and exciting feature is a multi-threaded SMP safe file system layer, which offers greatly enhanced performance for I/O bound systems such as database and email servers. In this release the ULE scheduler has been marked as safe for SMP systems.

Installing FreeBSD 6.1

FreeBSD uses a text based installation tool called Sysinstall. Debian, and Slackware users will feel right at home, while long time Red Hat users might need to adjust. The majority of the installer has gone unchanged, although there have been some minor improvements and additions (which will be noted).

Figure 1: FreeBSD’s installer booting
Figure 1: FreeBSD’s installer booting

The installation is the same as in the previous 5.x branch; however, there was a bug resulting in USB peripherals becoming unresponsive after the kernel loads that wasn’t fixed in the 6.0 release. If you experience this do the following: select option 6, and enter this: set hint.atkbd.0.flags="0x1" [hit enter] boot [hit enter].

The same line should be entered in the /boot/loader.conf file (after the installation) to prevent the USB peripherals from not working after the install: hint.atkbd.0.flags="0x1".

The 6.1 installer starts off with a new country selection screen (figure 2) which wasn’t present in previous versions.

Figure 2: Country selection
Figure 2: Country selection
Don't miss out on the other pages!
12345next ›last »

Write a full post in response to this!

0

Do you like this post?
Vote for it!

Copyright information

Verbatim copying and distribution of this entire article is permitted in any medium without royalty provided this notice is preserved.

Biography

Yousef Ourabi: Yousef Ourabi is a developer in the San Francisco bay area. He is currently working at the startup he recently founded, Zero-Analog. Zero-Analog is currently developing an enterprise application, however, one of its stated goals is "to increase the rate of open source adoption in companies of all sizes, across all industries". Zero-Analog also offers consulting services, all based around open source tools, frameworks and applications.

Anonymous visitor's picture

hmm...

Submitted by Anonymous visitor on Fri, 2006-10-27 02:09.

Vote!
0

does anybody know how to install bsd from hd-media?...(just like debian's initrd.gz vmlinuz...).
i think there're too few ways to install it,it's too unfriendly(maybe..)

Anonymous visitor's picture

If you havent idea, you have

Submitted by Anonymous visitor on Sat, 2006-10-28 22:26.

Vote!
0

If you havent idea, you have google dude :)
To be truthly, Im suprised why you want to install BSD from hdd ... enjoy it !

http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/install-pre.html

Anonymous visitor's picture

good

Submitted by Anonymous visitor on Mon, 2006-11-13 19:03.

Vote!
0

part 2 part 2 :))
part 1 is great!

Anonymous visitor's picture

Where is part2?

Submitted by Anonymous visitor on Wed, 2006-12-27 21:00.

Vote!
0

Where is part 2? Am I missing something?

admin's picture

Here is Part 2...

Submitted by admin on Thu, 2006-12-28 06:43.

Vote!
0

Hi,

Part 2 can be found in issue 15 right here.

Enjoy.

Bye

Robert Romberger's picture

Nice start...

Submitted by Robert Romberger on Mon, 2006-11-20 17:07.

Vote!
0

As was posted, Part Deux?

Anonymous visitor's picture

reason?

Submitted by Anonymous visitor on Thu, 2007-02-08 17:11.

Vote!
0

what a bunch of spoon-feeding. All of that is in the handbook already.

Ken Stox's picture

Small correction

Submitted by Ken Stox (not verified) on Tue, 2007-04-10 04:01.

Vote!
0

"Sun Microsystems earlier offering “SunOS” was based on BSD code from the early ’80s until the early ’90s when Sun released SunOS 4.0 based on AT&T’s SysV code."

All versions of SunOS up until 4.1.4 were based on BSD. SunOS 5.0 was the first to be based on Unix VR2. Sun retroactively named SunOS 4.1.X as Solaris 1.0, SunOS 5.0 was known as Solaris 2.0.

valen_willie's picture

My starting point

Submitted by valen_willie on Fri, 2007-06-01 09:00.

Vote!
0

Good article, I can use it to start learning FreeBSD now, some hands-on practices.

Jason Hirsh's picture

useless

Submitted by Jason Hirsh (not verified) on Sat, 2007-07-14 16:34.

Vote!
0

Ok so I installed all the software.. cool... HOW do you configure it.... squiremail is NOT fire and forget



CariNet: Cloud computing is a reality.

Other sites

Odiogo

Free Software Magazine uses Apollo, project management and CRM for its everyday activities!