Debian iTOps Tube

Tuesday, November 22, 2011

Sendmail Masquerading Explained

Sendmail Masquerading Explained

If you want your mail to appear to come from and not, then you have two choices:

  • Configure your email client, such as Outlook Express, to set your email address to (I'll explain this in the "Configuring Your POP Mail Server" section.).

  • Set up masquerading to modify the domain name of all traffic originating from and passing trough your mail server.

Configuring masquerading

In the DNS configuration, you made bigboy the mail server for the domain You now have to tell bigboy in the sendmail configuration file that all outgoing mail originating on bigboy should appear to be coming from; if not, based on our settings in the /etc/hosts file, mail will appear to come from This isn't terrible, but you may not want your Web site to be remembered with the word "mail" in front of it. In other words you may want your mail server to handle all email by assigning a consistent return address to all outgoing mail, no matter which server originated the email.

You can solve this by editing your configuration file and adding some masquerading commands and directives:


The result is that:

  • The MASQUERADE_AS directive makes all mail originating on bigboy appear to come from a server within the domain by rewriting the email header.
  • The MASQUERADE_DOMAIN directive makes mail relayed via bigboy from all machines in the and localdomain domains appear to come from the MASQUERADE_AS domain of Using DNS, sendmail checks the domain name associated with the IP address of the mail relay client sending the mail to help it determine whether it should do masquerading or not.
  • FEATURE masquerade_entire_domain makes sendmail masquerade servers named *, and * as In other words, mail from would be masqueraded as If this wasn't selected, then only servers named and would be masqueraded. Use this with caution when you are sure you have the necessary authority to do this.
  • FEATURE allmasquerade makes sendmail rewrite both recipient addresses and sender addresses relative to the local machine. If you cc: yourself on an outgoing mail, the other recipient sees a cc: to an address he knows instead of one on localhost.localdomain.

Note: Use FEATURE allmasquerade with caution if your mail server handles email for many different domains and the mailboxes for the users in these domains reside on the mail server. The allmasquerade statement causes all mail destined for these mailboxes to appear to be destined for users in the domain defined in the MASQUERADE_AS statement. In other words, if MASQUERADE_AS is and you use allmasquerade, then mail for enters the correct mailbox but sendmail rewrites the To:, making the e-mail appear to be sent to originally.

  • FEATURE always_add_domain always masquerades email addresses, even if the mail is sent from a user on the mail server to another user on the same mail server.
  • FEATURE masquerade_envelope rewrites the email envelope just as MASQUERADE_AS rewrote the header.

Masquerading is an important part of any mail server configuration as it enables systems administrators to use multiple outbound mail servers, each providing only the global domain name for a company and not the fully qualified domain name of the server itself. All email correspondence then has a uniform email address format that complies with the company's brand marketing policies.

Note: E-mail clients, such as Outlook Express, consider the To: and From: statements as the e-mail header. When you choose Reply or Reply All in Outlook Express, the program automatically uses the To: and From: in the header. It is easy to fake the header, as spammers often do; it is detrimental to e-mail delivery, however, to fake the envelope.

The e-mail envelope contains the To: and From: used by mailservers for protocol negotiation. It is the envelope's From: that is used when e-mail rejection messages are sent between mail servers.

Note: Be sure to run the script from the beginning of the chapter for these changes to take effect.

Testing Masquerading

The best way of testing masquerading from the Linux command line is to use the "mail -v username" command. I have noticed that "sendmail -v username" ignores masquerading altogether. You should also tail the /var/log/maillog file to verify that the masquerading is operating correctly and check the envelope and header of test email received by test email accounts.

Other Masquerading Notes

By default, user "root" will not be masqueraded. To remove this restriction use:


command in /etc/mail/ You can comment this out if you like with a "dnl" at the beginning of the line and running the sendmail start script.

No comments:

Post a Comment