Monday, March 8, 2010

10. Postfix Virtual Domains

    By default postfix has setup to handle few domains, defined by $mydestination. The idea of the virtual domain is to  map the multiple domains to the same server. " hostname -f " shows the FQDN also known as canonical domain used by Postfix.
Note: The IP address also considers as domain. For eg:- A message To: user@[] (The "[]" is must). So in this case the IP address is also considered as the domain. This domain is also considered as a part of the canonical domain.

Basic Virtual Domain Configuration

# vim /etc/postfix/
mydestination = $myhostname, localhost, $mydomain,,
relay_domains = $mydestination
# postfix reload
    Now the messages that destined to the domains listed in the $mydestination will be handled by the server. So messages send to a user at domain that defined at $mydestination will be delivered locally.
For Eg:- Mail send to and will get deliver to the same user in the host. In other words the list of domains that defined in the $mydestination will be considered to be local and delivers the mail locally.

Virtual Domains Using Maps For Single Domain
    This scenario is used ideally in a Linux mail server where the local users need to share the different domains, (used in ISP environment).
Splitting Local users in to separate domains
    To do so we have to setup the virtual aliases maps
# vim /etc/postfix/
virtual_alias_domains =
virtual_alias_maps = hash:/etc/postfix/virtual
     virtual_alias_domains tells what domains are needed to be supported by virtaul alias maps
# vim /etc/postfix/virtual    kiran    jam
# postmap /etc/postfix/virtual
   The format is as same as in the transport table. In the Left Hand Side we mention the address that need to be mapped and in Right Hand Side we mention the local or remote user mail address to which mail has to be delivered.
# postfix reload
Reload the postfix service

# postconf  | grep virtual_alias_
    Now test the setting by composing the msg to the user and The msg will be delivered to the local user kiran and jam respectively.

Virtual Domains Using catch all features.
    In a virtual alias map environment if mail is send to a non-existing Local user in a postfix server the mail will be rejected with the error "recipient address rejected" in log file. This situation could be overcome by defining the catchall address for the domain. But these feature will be subjected to catch all the mails that coming to the domain and obviously the server will be filled up with spam mails. So it is not at all considered to be used at production environment.
Defining the catch all
# vim /etc/postfix/
virtual_alias_domains =
virtual_alias_maps = hash:/etc/postfix/virtual
 # vim /etc/postfix/virtual    kiran
# postmap /etc/postfix/virtual
    Here all the mails that comes to the domain will be routed to user kiran.

The following virtual map file will send the all mails coming to the domain to multiple recipients.
# vim /etc/postfix/virtual    kiran, user1, user2, user3

The following virtual map will send the mails coming to user to remote domain
# vim /etc/postfix/virtual
Virtual alias Maps For Multiple Domains
    The following example shows the configuration of the multiple domains
# vim  /etc/postfix/
virtual_alias_domains =,,,
virtual_alias_maps = hash:/etc/postfix/virtual

# vim /etc/postfix/virtual             kiran               jam        jeo      paul        abuse

# postmap /etc/postfix/virtual
    This finishes the configuration of the Virtual alias maps
#postmap -q /etc/postfix/virtual
    The above command will query the virtual map file for the mapped address.
# postfix reload
    Test the settings by sending mails to each and every users in the new domains.
While testing this configuration make sure that the proper DNS entry in place.

No comments:

Post a Comment

tag ur valuable ideas below