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.
By using "relay_domains" derivative postfix is configured to relay mail from domains defined.
relay_domains = $mydestination
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.
# vim main.cf
relay_domains = $mydestination, new1domain.com, new2nd.domain.com
# smtpd_client_restrictions =
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.
# postfix reload
# ps -ef |grep master
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
Initially check for the Berkley DB packages are installed. These packages will be used by the postfix for database support.
# rpm -qa |grep db
Now postfix will refer the db file "/etc/postfix/relaydomains.db" for relaying.
# vim /etc/postfix/main.cf
relay_domains = $mydestination, hash:/etc/postfix/relaydomains
"postmap" generates the db file with respect to /etc/postfix/relaydomains.
# vim /etc/postfix/relaydomains
# postmap /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.
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.
# postfix reload#ps -ef |grep master