Tutorial: Virtual Hosting Email with Postfix

At this point, if you've performed the configuration in the previous tutorial, you'll be able to accept mail for any number of domains. However, this is not the same as providing independent virtual hosting support with Postfix, because you can only have one user of a given name and mail sent to that username at any of the domains for which you accept mail will be delivered to that user. So, for example, if you hosted swelltech.com, penguinfeet.org, and nostarch.com on the same server, and mail was sent to user joe at each of those domains, all three mails would end up in the same mailbox. Therefore, you have to introduce another layer to solve this problem.

Postfix has two commonly used methods for solving this problem. The first is the native Postfix method, using a virtual table to direct mail to the correct destination. The second method is modeled after the way Sendmail handles the problem, and is therefore a lot more complex. Because simplicity is better than complexity, you'll learn the native Postfix mechanism exclusively. The Postfix virtual man page covers both methods in moderate detail. If you have an older Sendmail installation that is being converted to Postfix you may wish to use the second method and maintain your current virtual mail configuration. If you will be running an extremely large number of virtual domains, it is likely preferable to use the second method, as well.

The first step for setting up virtual domain delivery is for you to create a virtual-map table using the Virtual Domains page (Figure 10-7). Enter the map type ( hash, dbm, and so on), followed by the filename of the flat file that will contain the table information. For example, you could use /etc/postfix/virtual for this purpose. This is a pretty common location for this file.

click to expand
Figure 10-7: The Virtual Domains table

Save and apply the change, and return to the Virtual Domains page. Now, you can click the New mapping button. You first have to create a generic map for the new domain. So, for the Name field, enter your virtual domain name. In the Maps to field, you can technically enter anything you like (as long as we enter something). The custom seems to be to enter virtual in this field, as that is its purpose. Click Save mapping to add it to the virtual table.

Next, you'll want to add a postmaster alias, as all mail servers must have a functioning postmaster address to be compliant with the relevant RFC. So, click New mapping again. This time enter postmaster@virtual.domain into the Name field, where virtual.domain is the name of your domain. Then enter postmaster into the Maps to field so that mail to this address will be mapped to the local postmaster address for normal delivery.

Finally, you're ready to start adding your virtual domain users to the table. Once again, create a new mapping. Fill in your new virtual domain mail address in the Name field. For example, you might fill in joe@virtual.domain. In the Maps to section, enter the name of a local user that you would like to receive mail for this address. In this case, you would use virtual-joe or perhaps virtual.domain.joe. This new local user must exist for mail to be delivered; therefore you'll need to add the new user to the system.

Now, Save and Apply your changes, and test it out! The virtual maps can be handled by various database types or exported to an LDAP database. There is no reasonable limit to the number of virtual users and domains you can have.



The Book of Webmin... or How I Learned to Stop Worrying and Love UNIX
The Book of Webmin: Or How I Learned to Stop Worrying and Love UNIX
ISBN: 1886411921
EAN: 2147483647
Year: 2006
Pages: 142
Authors: Joe Cooper

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net