Tuesday, March 2, 2010

7. Postfix Relay Domains


      This is an another way of enabling relaying in postfix. By default Postfix will relay mails for the domains that specified in the "mydestination" derivatives (Postfix considers the mail that are originated locally). If we need to add more domains to be relayed through the same server we can user "relay_domains" as well as "mydestination" derivatives.
By default "relay_domains" will be configured with mydestination.
i.e,
relay_domains = $mydestination
By using "relay_domains" derivative postfix is configured to relay mail from domains defined.
For example:
# vim main.cf
relay_domains = $mydestination, new1domain.com, new2nd.domain.com
# smtpd_client_restrictions =
Comment out the above derivative.The smtpd_client_restrictions parameter restricts what clients this system accepts SMTP connections from. By default, this restriction is applied when the client sends the RCPT TO command, the RCPT TO error in the log file points this error.
# postfix reload
# ps -ef |grep master
The above change will allow postfix to relay the mails from new1domain.com & new2nd.domain.com domains."smtpd_client_restrictions" makes the policy to reject the relay from other domains by default.
Note: All the subdomains will be relayed if a domain is specified in "relay_domains". For eg:- if newdomain.com is specified then postfix server will allow relaying all the subdomains like host1.newdomain.com, host2.newdomain.com etc.

Relay Domains with Maps
      Enabling the maps makes MTA to query the data from a database machanism. If a server is hosting many domains and practically entering each domain name in the configuration file is not possible, then we can use database maps for fast query and easier management.

Defining Rlay_domains Maps
# rpm -qa |grep db
Initially check for the Berkley DB packages are installed. These packages will be used by the postfix for database support.
# vim /etc/postfix/main.cf
relay_domains = $mydestination, hash:/etc/postfix/relaydomains
  Now postfix will refer the db file  "/etc/postfix/relaydomains.db" for relaying.
# vim /etc/postfix/relaydomains
domain1.com
domain2.com
domain3.com
domain4.com
domain5.com
# postmap /etc/postfix/relaydomains
"postmap" generates the db file with respect to /etc/postfix/relaydomains.
Note: The postmap utility will show error while running. It is because postmap expects the keys and values. The map file consist of keys and values separated with a white space. In our case we have only mentioned the keys. In a db map file Postmap expects the values for each key at right hand side. In this case the error is ignorable because this is the rare case that postfix will not read the "values" in the right hand side. Even if it shows the error the db file will be created.
# postfix reload
#ps -ef |grep master
  Now we will be able to relay mails from all the domains defined in the "relaydomains" file. After initializing Postfix a new entry to the file along with the postmap command is sufficient for postfix to relay to the newly added domain without restarting the service.

No comments:

Post a Comment

tag ur valuable ideas below