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:
define(`confSERVICE_SWITCH_FILE',`/etc/mail/service.switch')dnl
create the file /etc/mail/service.switch with these contents:
hosts files
add the email relay server entry to /etc/hosts
10.10.10.10 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
service.switch:
hosts dns nis files
aliases nis files