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.
Add this line to /etc/mail/sendmail.mc file:
create the file /etc/mail/service.switch with these contents:
add the email relay server entry to /etc/hosts
make -C /etc/mail
you should now have this line in /etc/mail/sendmail.cf:
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.
/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