Press "Enter" to skip to content

Forcing sendmail to use hosts file

In case you have a local network server and you want to send mail from it to a another server in the local network. You will need to bypass the DNS lookup for the hostname which the mail server performs by default by using sendmail.

You need to make sure that postfix is disable or uninstalled
service postfix stop
For Centos 6
chkconfig --del postfix
For Centos 7
/bin/systemctl disable sendmail.service

Remove postfix
yum remove postfix

Then make sure that postfix service is not run
ps aux | grep postfix

Now you need to edit the /etc/hosts file and add target mail server on the local network by adding your line like this e.g:    mail    mail.kfirman,com

yum install sendmail sendmail-cf sendmail-devel sendmail-milter m4

vi /etc/mail/mailertable
Add the mail server name and IP of the local network like this e.g:      esmtp:[]      esmtp:[]

makemap -v hash /etc/mail/mailertable < /etc/mail/mailertable

vi /etc/mail/
And comment out the DEAMON_OPTIONS(`Port-smtp,Addr=, Name=MTA')dnl.

m4 /etc/mail/ > /etc/mail/
/bin/systemctl start sendmail.service
/bin/systemctl enable sendmail.service

# go to the target mail server and see the log
tail -f /var/log/maillog

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *