The FreeBSD Diary |
(TM) | Providing practical examples since 1998If you buy from Amazon USA, please support us by using this link. |
Postfix - virtual domains
6 November 2002
|
||||||
This article concentrates on the installation and configuration of Postfix. The emphasis is on the FreeBSD environment although the basics should apply to most operating systems. Virtual domains are touched upon briefly, but Postfix - virtual domains contains more information about the three different types of virtual domains and is recommended reading for anyone contemplating implementation. Postfix is an MTA designed to be a replacement for sendmail as well as being fast, secure, and easy to configure. Why was it designed to replace sendmail? Easy. sendmail is a very widely used MTA with a quite complex configuration. It also handles most of the mail on the Internet not to mention the many private networks around the world. I have been running Postfix on some of my mail servers since August 2001. At least, that's when I think I first installed Postfix on this web server, which also doubles as a mail server. I've been happy with it mostly because I've been able to easily configure my virtual domains (i.e. handle mail for multiple domains) and block mail from certain sources. Postfix is now my MTA of choice. In this article, I will outline how to install Postfix and how to configure it to accept mail from more then one domain. I'm using virtual_mapping for my virtual domains. There are other ways to do virtual domains which are far more suitable for large scale operations. Search the newsgroup mailing.postfix.users for the phrase "Some notes on relay, local and virtual domains". |
||||||
README
|
||||||
It will be useful to read and understand the Postfix Anatomy. That will help you to understand how virtual address mapping, aliases, etc relate to the various Postfix components. Postfix has many different parts, each with a very distinct function. By keeping the programs smaller and with very distinct separation of tasks, it it both easier to code and to secure the system. And don't forget the Postfix FAQ. |
||||||
Installation
|
||||||
I install just about everything using the ports tree.
Right away you will be presented with the following choices. I wanted only
PCRE because of my header checks. If you don't
understand or need any of the optional components shown below, you can safely
omit it without worry.
I was asked this question during the install:*--------------------- Postfix configuration options ---------------------* | | | Please select desired options: | | *---------------------------------------------------------------------* | | | [X] PCRE Perl Compatible Regular Expressions | | | | [ ] SASL Cyrus SASL (Simple Authentication and Security Layer) | | | | [ ] DB3 Berkeley DB3 (required if SASL also built with DB3) | | | | [ ] MySQL MySQL map lookups | | | | [ ] PgSQL PostgreSQL map lookups | | | | [ ] OpenLDAP OpenLDAP map lookups | | | | [ ] Test SMTP/LMTP test server and generator | | | | [ ] TLS Secure Sockets Layer and Transport Layer Security | | | | [ ] IPv6 IPv6 support (not KAME official) | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | *---------------------------------------------------------------------* | *-------------------------------------------------------------------------* | [ OK ] Cancel | *-------------------------------------------------------------------------* As you can see, I said yes. I suggest you do the same. Then I was asked:Added group "postfix". Added group "maildrop". Added user "postfix". You need user "postfix" added to group "mail". Would you like me to add it [y]? y Done. For more information on mailer.conf, please read man 5 mailer.conf.Would you like to activate Postfix in /etc/mail/mailer.conf [n]? y On my P233 box, it took about 10 or 15 minutes to compile the code. During the install, you will see a couple of messages which you need to pay attention to (NOTE: The following is from Postfix 2.2.4,1) under FreeBSD 4.*:
The above was an install under 4.11. For a recent install of 6.0, the port told me to use use these settings instead:
For FreeBSD 7.0:
In both FreeBSD 4.* and 6.*, the following applied. You may wish to disable some Sendmail-specific daily maintenance
routines in your /etc/periodic.conf file:
I made those changes to my system as indicated above. I had to create |
||||||
Configuration
|
||||||
Postfix has a very well laid out configuration page. I urge you to read http://www.postfix.org/basic.html before proceeding. Understanding the rest of this article involves reading that URL first.
The primary configuration file for Postfix is |
||||||
Names used in this article
|
||||||
For the purposes of this article, we'll assume the hostname of the computer is gus.example.org (named after my cat). For those of you writing documentation for others, you should know that example.org is reserved for use in documentation. |
||||||
How to not mess up when making changes
|
||||||
When making configuration changes, I suggest using the SOFT BOUNCE feature of Postfix. Please refer
to |
||||||
What domain to use in outbound mail
|
||||||
I didn't make any changes here. I left things as the default. You may use to experiment with that. This is covered in What domain to use in outbound mail. |
||||||
What domains to receive mail for
|
||||||
For my example, gus is a stand-alone box. It does not handle mail for anything other than itself. Therefore, the default setting is sufficient.
This is covered in What domains to receive mail for.
|
||||||
Aliases
|
||||||
Aliases are documented under Postfix Configuration - Address Manipulation. The default setting is:
On FreeBSD systems, the file is actually /etc/mail/aliases . Therefore you should change this setting
to this:
After modifying an alias file, you should create the corresponding database file by issuing the following command:
|
||||||
That should be enough
|
||||||
With the above changes, I had enough to be able to send and receive mail on the box. But there's more. I want to create virtual domains and allow the box to handle mail for that too. |
||||||
What domains to receive mail for
|
||||||
The official documentation for this section is What domains to receive mail for. In this example, I will add two virtual domains to this box:
In the file /usr/local/etc/postfix/mydestination , I added the following entries
Then I restarted Postfix so it would reread the configuration file:
I was then able to send test messages to both dan@example.net and dan@example.com. This was OK for my
setup, but what if those are two different people? What you need then is virtual address mapping.
|
||||||
Virtual address mapping
|
||||||
The official documentation for this feature is Virtual address mapping. Virtual address mapping will allow you to map an address in a virtual domain to a real address. For example, let's assume there are two people named Dan on this box. One has a login of dan and the other has a login dtm. What we want is for the address translations to occur: To implement this in Postfix, we would add the following entry to the configuration file:
Then add this to the file /usr/local/etc/postfix/virtual_maps :
It is very important to know that these destination addresses are
actually @$mydomain , which in
this case is example.org . If you actually wish to deliver to local users and not
users in the given domain, then append @localhost to the names. For example:
Similarly, you can also forward the message to people in other domains:
Anything can be used in place of In this case, Postfix will accept the incoming mail and relay it to the mail servers for example.info and example.biz. After creating your mapping file, you need to create the database file from which Postfix will look up the mappings:
Then restart Postfix:
|
||||||
Virtual address mapping - yes, there's more!
|
||||||
In the above example, we put all of our virtual mappings into one file. If you have several domains, or many different virtual hosts, it might be useful to use multiple files. That's entirely optional.
For what it's worth, I actually put my mappings and aliases into another directory: |
||||||
What clients to relay mail for
|
||||||
The official documentation for this is What clients to relay mail for. By default, Postfix will relay mail for clients in authorized networks and in authorized domains.
The authorized networks setting is controlled by the WARNING! If your mail server is directly connected to a public network
(e.g. the Internet), make sure you set
Here is my setting for
This means that anyone on my local subnet (10.0.0.0/24) and on the machine itself (127.0.0.0/8) can send outgoing
mail through this host.
I discovered this problem with the following command:
The authorized domains setting is controlled by the |
||||||
Notice when running mergemaster during system upgrade
14 November 2002
| ||||||
If you are upgrading your system using make world, then remember to be careful
when it comes to upgrade
In case it is useful, here is my existing
|
||||||
Are you using logcheck/security?
|
||||||
If you are, you might want to add these entries to
For more information on logcheck:
|
||||||
What's an MTA? Many people would guess either Mail Transfer Agent or Mail Transport Agent. It can also mean Message Transfer Agent. Here are a few different definitions:
|
||||||