Previous TOC Next

Technical document: Linux Mail Server Howto
Chapter 3 - Installing Postfix

Downloading and compiling postfix

If you have sendmail already installed, you will want to avoid various things being over-written by postfix. As root:

> mv /usr/sbin/sendmail /usr/sbin/sendmail.OFF
> mv /usr/bin/newaliases /usr/bin/newaliases.OFF
> mv /usr/bin/mailq /usr/bin/mailq.OFF
> chmod 755 /usr/sbin/sendmail.OFF /usr/bin/newaliases.OFF /usr/bin/mailq.OFF

As a non-root user:

> cd
> wget http://postfix-release.colligatio.ch/official/postfix-2.5.1.tar.gz
> tar -xvf postfix-2.5.1.tar.gz
> cd postfix-2.5.1
> make

Creating postfix user and group

Before installing postfix you need to create a postfix user and group. As root:

> groupadd postfix

Get the group id (gid) that the group postfix has been created with:

> tail /etc/group

Then create the user:

> adduser -g [xxx] -c "Postfix" -s /sbin/nologin postfix

where [xxx] is the postfix group id. Finally create another group postdrop:

> groupadd postdrop

Now we are ready in install.

Installing postfix

To install a fresh new version of postfix, as root do:

> make install

Or if upgrading a current install, do:

> make upgrade

The fresh install is interactive, and you will have to answer various questions. Mostly the defaults should be fine, however you may wish to add ".postfix" to the following paths:

/usr/sbin/sendmail
/usr/bin/newaliases
/usr/bin/mailq

which will distinguish them from, and prevent any over-writing of, the sendmail equivalents. This postfix version of sendmail is compatible with the "real" sendmail and accepts exactly the same arguments. As various other system processes may be configured to call /usr/sbin/sendmail (for example the mailer mail), you should create a soft link:

> ln -s /usr/sbin/sendmail.postfix /usr/sbin/sendmail

Sendmail symbolic links

If you had sendmail installed on your system, there may be a number of symbolic links that need updating. These links are most likely in /etc/alternatives, and can be identified by doing:

> ln -s mta*

which may result in something like:

lrwxrwxrwx 1 root root 27 Mar 12 14:27 mta -> /usr/sbin/sendmail.sendmail
lrwxrwxrwx 1 root root 23 Mar 12 14:27 mta-mailq -> /usr/bin/mailq.sendmail
lrwxrwxrwx 1 root root 28 Mar 12 14:27 mta-newaliases -> /usr/bin/newaliases.sendmail
lrwxrwxrwx 1 root root 24 Mar 12 14:27 mta-pam -> /etc/pam.d/smtp.sendmail
lrwxrwxrwx 1 root root 23 Mar 12 14:27 mta-rmail -> /usr/bin/rmail.sendmail
lrwxrwxrwx 1 root root 26 Mar 12 14:27 mta-sendmail -> /usr/lib/sendmail.sendmail
Check for the postfix equivalents by doing:

> locate sendmail.postfix

and so on, and, if the postfix equivalent exists, update the link:

> ln -sf /usr/sbin/sendmail.postfix mta

Configuring postfix

This HOWTO assumes that postfix will be completely replacing any sendmail installation. Note that it is possible to use postfix and sendmail at the same time, or in conjunction with each other, splitting various tasks. However such set-ups are beyond the scope of this document.

Before starting postfix for the first time there are some mandatory configuration edits that must be applied. Postfix configuration files are all found in /etc/postfix. In /etc/postfix/main.cf you must specify values for the following parameters:

myorigin
mydestination
mynetworks

The parameter myorigin is the domain that locally posted mail will appear to originate from. A typical configuration would be to simply set this to your domain:

myorigin = $mydomain

The parameter mydestination details the list of domains that your server is the final destination for. This does not include any virtual domains you may be setting up. A typical configuration would be:

mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

Next you need to specify "trusted" IP addresses for which postfix should relay mail, which is specified with the mynetworks parameter. Postfix recognises the CIDR (Classless Inter-Domain Routing) format for specifying address ranges. A discussion of this is outside the scope of this document, however a good introduction may be found here. In this example, we relay mail for just two IP addresses:

mynetworks = 79.170.194.127/32, 127.0.0.1/32

You should also include any IP addresses which resolve to your machine, otherwise relaying for locally originating mail may be rejected.

It may not be necessary on all systems, but it's probably a good idea to set the myhostname parameter. By default postfix will use the fully-qualified host name according to gethostname(). However it seems that this does not always work, so you should manually set it just to be safe:

myhostname = mail.[domain]

You should also set the relay_domains parameter, which specifies what domains untrusted users are allowed to have mail relayed to. You probably want to turn this off (by default, mail addressed to the local domain will be relayed for untrusted users - which could result in a lot of spam):

relay_domains =

Finally, you should specify the mailbox to deliver to for system users. Unless specified, mail for system users will be delivered to your systems default mail drop - most likely an "mbox", which will be somewhere like /var/spool/mail/. However you probably want to use a maildir instead. To configure using a maildir directory in each users home directory:

home_mailbox = Maildir/

Make sure you include the trailing "/", this tells postfix the mailbox is in maildir format.

Creating postfix aliases

Postfix needs aliases for various non-system users to ensure that mail gets sent to a real (or the correct) person. There is an example file provided with postfix in /etc/postfix/aliases. A slightly more comprehensive example is here. Having created/updated a suitable aliases file, copy it to, or create a soft link in, /etc. Then you need to compile it:

> /usr/bin/newaliases

Note: if instead you called this /usr/bin/newaliases.postfix, you will have to either make a copy called /usr/bin/newaliases or create a soft link with the same name:

ln -s /usr/bin/newaliases.postfix /usr/bin/newaliases

otherwise with the ".postfix" extension the program will hang.

After running newaliases you should find a fresh /etc/aliases.db has been created.

Postfix log files

The location of system log files are defined here/etc/syslog.conf. Make sure as a very minimum you have something like this:

mail.*                                                  -/var/log/maillog

The "-" is not a typo, but a requirement on linux platforms for mail logging.

Switching off sendmail

If you have sendmail running on your system you'll need to turn it off before starting postfix. There are obviously issues with switching from one MTA to another on live systems processing a lot of mail. Full details of this are beyond the scope of this document, but basically you need to stop sendmail and restart it in queue-processing mode:

/etc/rc.d/init.d/sendmail stop

In theory this should stop sendmail. If it doesn't, do:

> ps ax | grep sendmail

to get the process ids of all running sendmail processes, and kill them manually. To restart sendmail in queue-processing mode, do:

> /usr/sbin/sendmail.OFF -q

which will not start the sendmail daemon but will flush any mails queued. Depending on the size of your system and delivery issues to remote hosts, this may take some time.

Starting and stopping postfix

Postfix can be started by doing:

> postfix start

and stopped by doing:

> postfix stop

A running mail system can be updated after configuration edits by doing:

> postfix reload

Testing postfix

Having started postfix we should check it is woking as expected. First let's check that port 25 is open:

> netstat -anp | grep :25

should produce something like:

tcp        0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN      1905/master

Now check that we can send mail to external addresses:

> mail [someone]@[somedomain]

Check that mail can be sent internally and is being delivered properly:

> mail [user]

Make sure that you have a Maildir directory for [user]. Otherwise mail will be delivered to the system spool. There is a tool that is bundled with courier-imap for creating maildir directories, but all you really need to do is simply (as the user) create the directory:

> su [user]
> cd
> mkdir Maildir

When delivering mail to a maildir directory, postfix will create three sub-directories cur, new and tmp if they do not already exist. Check in new for new mails.

Finally, check that mail is being delivered from outside correctly by sending [user] a mail from some other account or system. If it is all working, then congratulations! You have set up postfix to send and deliver email for your system users. Next we will install authdaemond and courier-imap to provide an IMAP interface to system mailboxes.

Note: there is actually one more task we need to do: switching off sendmail and turning on postfix at boot time. This is discussed in the tieing-it-all-together page here.

Previous: Chapter 2 - Introduction TOC Next: Chapter 4 - Installing authdaemond