JBY Technologies

Configuring Sendmail To Use The Hosts File

Sometimes you may need to relay email through a mail server that is not set up in dns, or that has a public ip in dns and you want to use the private ip. Sendmail requires a configuration setting before it will use the hosts file.

cd /etc/mail

Add this line to /etc/mail/sendmail.mc file:


create the file /etc/mail/service.switch with these contents:

hosts files

add the email relay server entry to /etc/hosts   relay.example.com

make -C /etc/mail

you should now have this line in /etc/mail/sendmail.cf:

O ServiceSwitchFile=/etc/mail/service.switch

Note: if nothing happens when you run make -C /etc/mail, you may be missing the sendmail-cf package. If your Linux is a recent Redhat or Centos, you can probably just install it with yum: yum -y install sendmail-cf.

restart sendmail...

/sbin/service sendmail restart

and verify that sendmail uses the hosts entry by sending an email and reviewing the /var/log/maillog log file

starting with HP-UX 11.0, HP-UX does not support service.switch in sendmail. However, the same functionality is available using the /etc/nsswitch.conf file:

These two lines in the /etc/nsswitch.conf are equivalent to the below in the /etc/mail/service.switch file:

sendmailvars:     dns nis files
aliases:      nis files


hosts    dns nis files
aliases  nis files

Bookmark and Share

Legal Notices