• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How To Masquerade Sender Address In Sendmail in CentOS/RHEL

by admin

You would like to configure your sendmail server to masquerade the sender address to no-reply@target-domain.net when sending emails from it.

The Solution

Normally to masquerade a domain, the “MASQUERADE_AS” and “MASQUERADE_DOMAIN” is used in /etc/mail/sendmail.mc. But that will leave the user unchanged. With sendmail, you can change both the domain and username on a case-by-case basis using the genericstable feature.

1. make sure all the “MASQUERADE” items are commented out in /etc/mail/sendmail.mc. Be noted the lines starting with “dnl” are meant to be commented.

# grep 'MASQUERADE' /etc/mail/sendmail.mc
dnl # MASQUERADE_AS(`target-domain.net')dnl
dnl MASQUERADE_DOMAIN(localhost)dnl
dnl MASQUERADE_DOMAIN(localhost.localdomain)dnl
dnl MASQUERADE_DOMAIN(domain-to-masquerade.net)dnl

2. Enable domaintable feature:

# grep domaintable sendmail.mc
FEATURE(domaintable)
# cat domaintable
domain-to-masquerade.net   target-domain.net

3. Configure “genericstable” in /etc/mail/sendmail.mc by adding the following lines in it.

FEATURE(`genericstable',`hash -o /etc/mail/genericstable.db')dnl
GENERICS_DOMAIN_FILE(`/etc/mail/generics-domains')dnl

4. Fill /etc/mail/generics-domains.

target-domain.net

5. Fill /etc/mail/genericstable.

root no-reply@target-domain.net
other-user1 no-reply@target-domain.net
other-user2 no-reply@target-domain.net

6. Recompile /etc/sendmail.mc:

# cd /etc/mail
# make

You may get the following error while doing so:

# make
WARNING: 'sendmail.mc' is modified. Please install package sendmail-cf to update your configuration.

It is due to missing of sendmail-cf package and please install it to proceed.

# yum install sendmail-cf
# cd /etc/mail
# make

7. Restart sendmail service.

# service sendmail restart
Shutting down sm-client:    [ OK ]
Shutting down sendmail:     [ OK ]
Starting sendmail:          [ OK ]
Starting sm-client:         [ OK ]

8. Test and verify.

# hostname
domain-to-masquerade.net
# echo "This is a test mail to verify the sendmail sender masquerade." | mailx -s "Test Sender Masquerade" your-name@your-email.com

Make sure “target-domain.net” are Full Qualified Domain Name(FQDN). That means the domain name should be resolvable by the target mail server from the authoritative DNS servers. Otherwise, the mail will most likely be rejected.

Filed Under: CentOS/RHEL 5, CentOS/RHEL 6, Linux

Some more articles you might also be interested in …

  1. hostnamectl: command not found
  2. faketime: command not found
  3. How to add Swap Space on Linux Servers (CentOS/RHEL) On the Fly
  4. CentOS / RHEL : How to extend Physical Volume in LVM by extending the Disk Partition used
  5. mkfs.xfs: command not found
  6. bc: command not found
  7. Oracle OS watcher (OSWatcher) – Understanding oswmpstat
  8. Unable To Extend LVM File System with Associated Snapshot in CentOS/RHEL
  9. flatpak Command Examples in Linux
  10. backlight_control Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • pw-cat Command Examples in Linux
  • pvs: command not found
  • pulseaudio: command not found
  • pulseaudio Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright