Setting up a Postfix Mail Forwarder
Created: 01/27/2005
Introduction
If you run a groupware email server on your LAN like Microsoft Exchange, Lotus Notes, or similar, setting up a secure mail forwarder is a good alternative to opening port 25 from the Internet directly to your LAN server. Typically with these servers, you don't want to put them on a DMZ segment for performance reasons, but you have to let in email from the Internet. Opening a port to these servers, and into your LAN, can be risky.Example Infrastructure
The following diagram depicts a typical setup of this type. The mail forwarder sits in the DMZ, with the groupware mail server on the LAN. The DNS MX records for your domain(s) point to the mail forwarder. You can set up two identical forwarders, one for a primary MX, and one for a secondary, for redundancy.
Firewall Configuration
The firewall allows TCP 25 (SMTP) inbound to the mail forwarder. The mail forwarder is allowed to talk only to port 25 on the LAN mail server. This way even if the forwarder were to be compromised, its only access to the LAN is port 25 on your mail server. The chances of compromising the mail forwarder and then compromising the LAN through only TCP 25 on the mail server are slim to none. I would configure the firewall so it cannot talk out to anything but TCP 25 on the mail server, and possibly a NTP server (on the Internet or LAN) to synchronize time. Strictly limiting what outbound access the forwarder is allowed will make an attacker's job more difficult, as they will usually attempt to download tools, a root kit, or similar onto a compromised system. You'll need to permit outbound HTTP (TCP port 80), cvsup (TCP 5999), and DNS (UDP 53) during the initial setup and while performing updates, but should leave them closed during normal operation.Hardware Requirements
In future articles, I plan to cover adding spam and virus filtering to this basic setup. If you want to simply forward mail without much processing like antivirus or spam protection, a very low power system will work fine. The lowest power system I have running a setup similar to this is a Pentium Pro 200 MHz with 128 MB RAM. It processes over 5,000 messages a day, and the load average stays around 0.05. It has a simple filtering setup, nothing nearly as taxing as any of the common spam filtering and virus scanning packages. The lowest powered setup of this nature I have is a Duron 800 MHz setup with FreeBSD, Postfix and SpamAssassin. It processes about 1500-2000 messages a day, with a typical load average of 0.02.Suggested Minimum Requirements
Requirements
Installation
First we'll install Postfix.|
# # |
cd /usr/ports/mail/postfix make install clean |
|
You need user "postfix" added to group "mail". Would you like me to add it [y]? |
|
Would you like to activate Postfix in /etc/mail/mailer.conf [n]? |
|
sendmail_enable="NONE" |
|
# # |
cd /usr/local/etc/rc.d ln -s /usr/local/sbin/postfix postfix.sh |
|
daily_clean_hoststat_enable="NO" daily_status_mail_rejects_enable="NO" daily_status_include_submit_mailq="NO" daily_submit_queuerun="NO" |
Configuration
Postfix configuration files live in /usr/local/etc/postfix/.main.cf Configuration
First we'll edit main.cf. You'll need to change four lines|
myhostname = mail.example.com |
|
mydomain = example.com |
|
relay_domains = example.com example.org example.net |
|
local_recipient_maps = |
transport Configuration
Next open the file called transport. This file contains only comments in the default installation. Go down to the bottom of the file. You'll need to enter something like the following, one line per domain.|
example.com smtp:[10.0.0.2] example.net smtp:[10.0.0.2] example.org smtp:[10.0.0.2] |
| # | postmap /usr/local/etc/postfix/transport |
Testing the Configuration
First we'll make sure there are no syntax errors in your configuration files.| # | postfix check |
|
# postfix start postfix/postfix-script: starting the Postfix mail system |
|
220 mail.example.com ESMTP Postfix helo mailtest.example.com 250 mail.example.com mail from:user@domain.com 250 Ok rcpt to:user@example.com 250 Ok data 354 End data with <CR><LF>.<CR><LF> hello . 250 Ok: queued as 9B7A94F6454 |
| # | cat /var/log/maillog |
|
Jan 25 10:19:44 mail postfix/smtp[81162]: 72062EB: to=<user@example.com>, relay=10.0.0.2[10.0.0.2], delay=0, status=sent (250%202.6.0%20%3C20050125382.A382373DKDF@mail.remotedomain.com%3E%20Queued%20mail%20for%20delivery">250 2.6.0 <20050125382.A382373DKDF@mail.remotedomain.com> Queued mail for delivery |
Conclusion
After following this guide, you have a solid, secure, reliable mail forwarder in place to protect your more fragile groupware LAN mail server and help keep your network more secure. Look for future articles on adding spam filtering and antivirus scanning capabilities to this basic configuration.Author: Chris Buechler
bsdguides at chrisbuechler dot com