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@[10.0.0.1] (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/main.cf
mydestination = $myhostname, localhost, $mydomain, anewdomain.com, someotherdomain.com
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. mydestination = $myhostname, localhost, $mydomain, anewdomain.com, someotherdomain.com
relay_domains = $mydestination
# postfix reload
For Eg:- Mail send to kiran@anewdomain.com and kiran@someotherdomain.com 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/main.cf
virtual_alias_domains = example.com
virtual_alias_maps = hash:/etc/postfix/virtual
virtual_alias_domains tells what domains are needed to be supported by virtaul alias mapsvirtual_alias_domains = example.com
virtual_alias_maps = hash:/etc/postfix/virtual
# vim /etc/postfix/virtual
userdd@example.com kiran
dduser@example.com 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.userdd@example.com kiran
dduser@example.com jam
# postmap /etc/postfix/virtual
# postfix reload
Reload the postfix service# postconf | grep virtual_alias_
Now test the setting by composing the msg to the user userdd@example.com and dduser@example.com. 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/main.cf
virtual_alias_domains = example.com
virtual_alias_maps = hash:/etc/postfix/virtual
# vim /etc/postfix/virtual
@example.com kiran
# postmap /etc/postfix/virtual
Here all the mails that comes to the domain example.com will be routed to user kiran.virtual_alias_domains = example.com
virtual_alias_maps = hash:/etc/postfix/virtual
# vim /etc/postfix/virtual
@example.com kiran
# postmap /etc/postfix/virtual
The following virtual map file will send the all mails coming to the domain example.com to multiple recipients.
# vim /etc/postfix/virtual
@example.com kiran, user1, user2, user3
@example.com kiran, user1, user2, user3
The following virtual map will send the mails coming to user kiran@example.com to remote domain kiran@secureserver.com.
# vim /etc/postfix/virtual
kiran@example.com kiran@secureserver.com
kiran@example.com kiran@secureserver.com
Virtual alias Maps For Multiple Domains
The following example shows the configuration of the multiple domains
# vim /etc/postfix/main.cf
virtual_alias_domains = firstdomain.com, seconddomain.net, thirddomain.org, fourthdomain.com
virtual_alias_maps = hash:/etc/postfix/virtual
# vim /etc/postfix/virtual
sales@firstdomain.com kiran
hr@seconddomain.net jam
finance@thirddomain.org jeo
project@fourthdomain.com paul
abuse@seconddomain.net abuse
# postmap /etc/postfix/virtual
This finishes the configuration of the Virtual alias mapsvirtual_alias_domains = firstdomain.com, seconddomain.net, thirddomain.org, fourthdomain.com
virtual_alias_maps = hash:/etc/postfix/virtual
# vim /etc/postfix/virtual
sales@firstdomain.com kiran
hr@seconddomain.net jam
finance@thirddomain.org jeo
project@fourthdomain.com paul
abuse@seconddomain.net abuse
# postmap /etc/postfix/virtual
#postmap -q abuse@seconddomain.net /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