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.
1) Basic Virtual Domain Configuration
For Eg:- Mail send to user123@anewdomain.com and user123@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.
2) 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
3) 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
and email destined to testing99@himali.external will be routed to orange(local user)
The following virtual map file will send the all mails coming to the domain example.com to multiple recipients.
4) Virtual alias Maps For Multiple Domains
The following example shows the configuration of the multiple domains
#postmap -q abuse@seconddomain.net /etc/postfix/virtual
The above command will query the virtual map file for the mapped address.
example:
postmap -q user45@samsung.ext virtual
user45 #result
postmap -q nep123@sky.net virtual
somebody@google.com #result
# 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.
SOME LOGS Generated at my test enviroment
LOG MESSAGE @SENDING SERVER-->nepal.external
sender user = hellboy destination = nonexistent user (which is redirected to hellboy itself for test purpose)
Jun 10 23:38:20 mailvm postfix/pickup[1582]: 8F5F9FF345: uid=500 from=<hellboy>
Jun 10 23:38:20 mailvm postfix/cleanup[1636]: 8F5F9FF345: message-id=<20140610175320.GA1631@mailvm.nepal.external>
Jun 10 23:38:20 mailvm postfix/qmgr[1583]: 8F5F9FF345: from=<hellboy@nepal.external>, size=472, nrcpt=1 (queue active)
Jun 10 23:38:20 mailvm postfix/smtp[1638]: 8F5F9FF345: to=<nonexistuser@himali.external>, relay=mailvm.himali.external[192.168.140.200]:25, delay=0.1, delays=0.05/0.01/0.02/0.02, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 910FAFF644)
Jun 10 23:38:20 mailvm postfix/qmgr[1583]: 8F5F9FF345: removed
Jun 10 23:38:20 mailvm postfix/smtpd[1639]: connect from mailvm.urgens.com[192.168.140.200]
Jun 10 23:38:20 mailvm postfix/smtpd[1639]: A3682FF328: client=mailvm.urgens.com[192.168.140.200]
Jun 10 23:38:20 mailvm postfix/cleanup[1636]: A3682FF328: message-id=<20140610175320.GA1631@mailvm.nepal.external>
Jun 10 23:38:20 mailvm postfix/qmgr[1583]: A3682FF328: from=<hellboy@nepal.external>, size=846, nrcpt=2 (queue active)
Jun 10 23:38:20 mailvm postfix/smtpd[1639]: disconnect from mailvm.urgens.com[192.168.140.200]
Jun 10 23:38:20 mailvm postfix/local[1641]: A3682FF328: to=<hellboy@nepal.external>, relay=local, delay=0.01, delays=0/0.01/0/0, dsn=2.0.0, status=sent (delivered to mailbox)
Jun 10 23:38:20 mailvm postfix/local[1641]: A3682FF328: to=<root@nepal.external>, relay=local, delay=0.02, delays=0/0.01/0/0, dsn=2.0.0, status=sent (delivered to mailbox)
Jun 10 23:38:20 mailvm postfix/qmgr[1583]: A3682FF328: removed
LOG @RECEIVING SERVER-->urgens.internal
Jun 10 17:59:37 mailvm postfix/smtpd[2119]: connect from unknown[192.168.140.20]
Jun 10 17:59:37 mailvm postfix/smtpd[2119]: 2D277FF644: client=unknown[192.168.140.20]
Jun 10 17:59:37 mailvm postfix/cleanup[2122]: 2D277FF644: message-id=<20140610180013.GB1631@mailvm.nepal.external>
Jun 10 17:59:37 mailvm postfix/qmgr[2104]: 2D277FF644: from=<hellboy@nepal.external>, size=636, nrcpt=2 (queue active)
Jun 10 17:59:37 mailvm postfix/smtpd[2119]: disconnect from unknown[192.168.140.20]
Jun 10 17:59:37 mailvm postfix/smtp[2123]: 2D277FF644: to=<hellboy@nepal.external>, orig_to=<noexistuser@himali.external>, relay=mailvm.nepal.external[192.168.140.20]:25, delay=0.04, delays=0.01/0.01/0.02/0.01, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 3F8E9FF328)
Jun 10 17:59:37 mailvm postfix/smtp[2123]: 2D277FF644: to=<root@nepal.external>, orig_to=<noexistuser@himali.external>, relay=mailvm.nepal.external[192.168.140.20]:25, delay=0.04, delays=0.01/0.01/0.02/0.01, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 3F8E9FF328)
Jun 10 17:59:37 mailvm postfix/qmgr[2104]: 2D277FF644: removed
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.
1) 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 user123@anewdomain.com and user123@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.
2) 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 maps
virtual_alias_domains = example.com
virtual_alias_maps = hash:/etc/postfix/virtual
# vim /etc/postfix/virtual
##LHS (email addr) ---> RHS(Local and/or remote address)
apple@himali.external apple
orange@himali.external orange
##any thing else destined to ...@himali.external will be sent to internal/external-user on the RHS
@himali.external catchit
# 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.
##LHS (email addr) ---> RHS(Local and/or remote address)
apple@himali.external apple
orange@himali.external orange
##any thing else destined to ...@himali.external will be sent to internal/external-user on the RHS
@himali.external catchit
# 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 users apple and orange respectively.3) 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
##LHS (email addr) ---> RHS(Local and/or remote address)
apple@himali.external apple
testing99@himali.external orange
##any thing else destined to ...@himali.external will be sent to internal/external-user on the RHS
@himali.external catchit
# postmap /etc/postfix/virtual
now email destined to apple@himali.external will be routed to apple (local user)##LHS (email addr) ---> RHS(Local and/or remote address)
apple@himali.external apple
testing99@himali.external orange
##any thing else destined to ...@himali.external will be sent to internal/external-user on the RHS
@himali.external catchit
# postmap /etc/postfix/virtual
and email destined to testing99@himali.external will be routed to orange(local user)
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 catchit,user1, user2, user3
The following virtual map will send the mails coming to user don@example.com to remote domain nepal@secureserver.com.
@example.com catchit,user1, user2, user3
# vim /etc/postfix/virtual
DON@example.com nepal@secureserver.com
DON@example.com nepal@secureserver.com
4) 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 satriani
hr@seconddomain.net joe
finance@thirddomain.org david
project@fourthdomain.com paul
abuse@seconddomain.net abuse
# postmap /etc/postfix/virtual
This finishes the configuration of the Virtual alias maps
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 satriani
hr@seconddomain.net joe
finance@thirddomain.org david
project@fourthdomain.com paul
abuse@seconddomain.net abuse
# postmap /etc/postfix/virtual
#postmap -q abuse@seconddomain.net /etc/postfix/virtual
example:
postmap -q user45@samsung.ext virtual
user45 #result
postmap -q nep123@sky.net virtual
somebody@google.com #result
# postfix reload
While testing this configuration make sure that the proper DNS entry in place.
SOME LOGS Generated at my test enviroment
LOG MESSAGE @SENDING SERVER-->nepal.external
sender user = hellboy destination = nonexistent user (which is redirected to hellboy itself for test purpose)
Jun 10 23:38:20 mailvm postfix/pickup[1582]: 8F5F9FF345: uid=500 from=<hellboy>
Jun 10 23:38:20 mailvm postfix/cleanup[1636]: 8F5F9FF345: message-id=<20140610175320.GA1631@mailvm.nepal.external>
Jun 10 23:38:20 mailvm postfix/qmgr[1583]: 8F5F9FF345: from=<hellboy@nepal.external>, size=472, nrcpt=1 (queue active)
Jun 10 23:38:20 mailvm postfix/smtp[1638]: 8F5F9FF345: to=<nonexistuser@himali.external>, relay=mailvm.himali.external[192.168.140.200]:25, delay=0.1, delays=0.05/0.01/0.02/0.02, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 910FAFF644)
Jun 10 23:38:20 mailvm postfix/qmgr[1583]: 8F5F9FF345: removed
Jun 10 23:38:20 mailvm postfix/smtpd[1639]: connect from mailvm.urgens.com[192.168.140.200]
Jun 10 23:38:20 mailvm postfix/smtpd[1639]: A3682FF328: client=mailvm.urgens.com[192.168.140.200]
Jun 10 23:38:20 mailvm postfix/cleanup[1636]: A3682FF328: message-id=<20140610175320.GA1631@mailvm.nepal.external>
Jun 10 23:38:20 mailvm postfix/qmgr[1583]: A3682FF328: from=<hellboy@nepal.external>, size=846, nrcpt=2 (queue active)
Jun 10 23:38:20 mailvm postfix/smtpd[1639]: disconnect from mailvm.urgens.com[192.168.140.200]
Jun 10 23:38:20 mailvm postfix/local[1641]: A3682FF328: to=<hellboy@nepal.external>, relay=local, delay=0.01, delays=0/0.01/0/0, dsn=2.0.0, status=sent (delivered to mailbox)
Jun 10 23:38:20 mailvm postfix/local[1641]: A3682FF328: to=<root@nepal.external>, relay=local, delay=0.02, delays=0/0.01/0/0, dsn=2.0.0, status=sent (delivered to mailbox)
Jun 10 23:38:20 mailvm postfix/qmgr[1583]: A3682FF328: removed
LOG @RECEIVING SERVER-->urgens.internal
Jun 10 17:59:37 mailvm postfix/smtpd[2119]: connect from unknown[192.168.140.20]
Jun 10 17:59:37 mailvm postfix/smtpd[2119]: 2D277FF644: client=unknown[192.168.140.20]
Jun 10 17:59:37 mailvm postfix/cleanup[2122]: 2D277FF644: message-id=<20140610180013.GB1631@mailvm.nepal.external>
Jun 10 17:59:37 mailvm postfix/qmgr[2104]: 2D277FF644: from=<hellboy@nepal.external>, size=636, nrcpt=2 (queue active)
Jun 10 17:59:37 mailvm postfix/smtpd[2119]: disconnect from unknown[192.168.140.20]
Jun 10 17:59:37 mailvm postfix/smtp[2123]: 2D277FF644: to=<hellboy@nepal.external>, orig_to=<noexistuser@himali.external>, relay=mailvm.nepal.external[192.168.140.20]:25, delay=0.04, delays=0.01/0.01/0.02/0.01, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 3F8E9FF328)
Jun 10 17:59:37 mailvm postfix/smtp[2123]: 2D277FF644: to=<root@nepal.external>, orig_to=<noexistuser@himali.external>, relay=mailvm.nepal.external[192.168.140.20]:25, delay=0.04, delays=0.01/0.01/0.02/0.01, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 3F8E9FF328)
Jun 10 17:59:37 mailvm postfix/qmgr[2104]: 2D277FF644: removed
No comments:
Post a Comment