Force sendmail to route mail to specific hosts or mailserver

mailertable allows you to route or deliver mail to different hosts. You need to use feature called FEATURE(`mailertable’) and you will have to create an external database containing the routing information for various domains.

First include mailertable feature you need to edit your file and add the following line:

Open sendmail config file using text editor:

# vi /etc/mail/

Append/modify line as follows:


Regenerate sendmail configuration file using m4:

m4 /etc/mail/ > /etc/mail/

Restart sendmail service:

# /etc/init.d/sendmail restart

Open /etc/mail/mailertable file and add domain name to route to different hosts. For example all mail coming from network 192.168 route to and all email for will be automatically forwarded to a mail server

# vi /etc/mail/mailertable

Append following lines:


Now build database version of the mailertable is built using:

# makemap hash /etc/mail/mailertable Or just type make command to build new mailertable.db file:
# make

See also:

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 4 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
4 comments… add one
  • nilesh Dec 24, 2006 @ 8:33

    I have a centos & I use sendmail as mail server.
    In I had put an IP Address of relay server. & All mail is sending properly but My mail server administrator told me to put host name instead of IP address in SmartHost Ds in & I done it but I cant send mail to anybody & I got an error —

    451 4.4.1 reply: read error from

    Please anybody tell me How can I send mail to outside via my relay using host name & what should I do?

  • relocation Jul 18, 2007 @ 2:09

    How can we use the other port?

    for example,use port 2525.

  • Martin Dahl-Larsen Jan 7, 2012 @ 23:45

    Hi there

    Just add this line to
    and rebuild


  • vinayak Jun 7, 2017 @ 15:46

    I have mail server on redhat and its sendmail configured as relay for office 365 mail services

    It was wokring fine for 3 months but now its not working as expected mails are getting very slow delivered with delay from 30 minutes to 24 or 48 hours

    These are output of error

    Jun 7 18:55:25 app2 sendmail[82004]: v57D4r4a061245: to=, delay=00:20:32, xdelay=00:00:00, mailer=esmtp, pri=212172, relay=…..mail…, dsn=4.0.0, stat=Deferred: Connection timed out with …

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum