Address masquerading refers to the idea that you can hide the names of internal hosts, and make all addresses appear as if they originated from the gateway system itself. You may have internal systems that use your Postfix server as a gateway. When mail is sent from these systems and the sender addresses include the fully qualified hostname, you may want addresses to appear with the domain name only. The masquerade_domains parameter strips hostnames down to their simpler domain names.
The parameter takes a list of domains. Any address whose fully qualified hostname matches the domain portion is stripped down to just the domain name:
root# vim /etc/postfix/main.cf
masquerade_domains = domain.com
Addresses that look like email@example.com and firstname.lastname@example.org are converted to email@example.com and firstname.lastname@example.org.
You can list multiple domains and subdomains. Postfix processes addresses against masquerade domain names in the order you list them. Consider a network that includes the two subdomains, acct.example.com and hr.example.com. You want addresses from these domains to show the subdomain, but you want addresses from any other domain or host in the network to show the parent domain. Set masquerade_domains as follows:
masquerade_domains = srv.domain.com srv1.domain.com domian.com
With this setting, the address email@example.com matches srv.domain.com, so that it becomes firstname.lastname@example.org.
The address email@example.com matches srv1.domain.com, and becomes firstname.lastname@example.org. Finally, email@example.com matches the last value, domain.com, to become firstname.lastname@example.org.
If you want to preserve a domain name that would otherwise be stripped down, you can preface the domain with an exclamation point:
masquerade_domains = !srv2.domain.com, domain.com
In this case, the domain srv2.domain.com will not be rewritten, so the address email@example.com stays as it is.
You can exclude specific account names from masquerading. For example, if you want an address like root@srv10_prod.example.com to stay intact, add the account to the masquerade_exceptions parameter:
masquerade_exceptions = admin, root
root# /etc/init.d/./postfix restart