MBF Knowledge Base

How do I set up virtual domains in Postfix?

1. Edit /etc/postfix/virtual

This is a plaintext file where you can specify the domains and users to accept mail for. Each virtual domain should begin with a single line containing the domain name. The subsequent lines define addresses at the domain that are deliverable. Mail will be delivered to local usernames on the right side, as demonstrated in the example below. The condition @domain allows you to deliver "all other" mail to the indicated user. You can list multiple domains in this file; just repeat the format demonstrated below.

example.com        this-text-is-ignored
postmaster@example.com    postmaster
address1@example.com    destuser1
address2@example.com    destuser2
@example.com        destuser1

 

2. Edit /etc/postfix/main.cf

You have to tell Postfix where to look for these virtual alias mappings; the appropriate configuration directive is in the main Postfix configuration file. This tells Postfix to use the db-format (hash) version of your virtual mappings. Note that your system must have db support for this to work; also, the actual db file is not created until you run 'postmap' in step 3.

virtual_alias_maps = hash:/etc/postfix/virtual

 

3. Refresh configuration and mappings

Since you've changed main.cf, you should restart the daemon. The second command below updates the virtual mappings; you must run this 'postmap' command when you change your /etc/postfix/virtual file. The 'postmap' command actually creates the hash db file that Postfix looks for.

postfix reload
postmap /etc/postfix/virtual