How to force Sendmail to use smarthost without DNS
Q:Why would anyone want to do that?!
A:In an enterprise or a large corporation you usually have a central (or several centralised) incoming and outgoing email servers. Running Sendmail on port 25 and delivering email without a smarthost on every server around is just nonsense. If you don't receive incoming email and just want to send outbound email you can get away with just "submit" part of Sendmail, no port 25 listener and not even the suid bit. Also many Linux servers hosted in those environments don't access Internet directly and for several other purposes it's beneficial not to have DNS resolver configured on them at all. In such case you need to force sendmail to use hosts file to resolve smart host name.
  • If you're on RHEL you need sendmail-cf rpm.
  • First make sure your smarthost is in /etc/hosts
  • Create /etc/mail/service.switch file and put following two lines inside:
    hosts   files
    aliases files
    
  • Create /etc/mail/submit.mc file (or replace it's contents) with:
    divert(0)dnl
    include(`/usr/share/sendmail-cf/m4/cf.m4')
    VERSIONID(`linux setup for RHEL')dnl
    define(`confCF_VERSION', `Submit')dnl
    define(`__OSTYPE__',`')dnl dirty hack to keep proto.m4 from complaining
    define(`confTIME_ZONE', `USE_TZ')dnl
    define(`confDONT_INIT_GROUPS', `True')dnl
    define(`confPID_FILE', `/var/run/sm-client.pid')dnl
    define(`SMART_HOST',`my smarthost from /etc/hosts')dnl
    define(`PROCMAIL_MAILER_PATH',`/usr/bin/procmail')dnl
    define(`ALIAS_FILE', `/etc/aliases')dnl
    MASQUERADE_AS(`Your DNS domain: example.com')dnl
    FEATURE(masquerade_envelope)dnl
    FEATURE(masquerade_entire_domain)dnl
    FEATURE(`use_ct_file')dnl
    MAILER(smtp)dnl
    MAILER(procmail)dnl
    
  • Go to /etc/mail and type "make" to build new submit.cf. That will get you working outgoing email using dedicated smarthost without DNS lookups. Unless your host is really receiving email and you have real users (or software) reading it you can stop Sendmail daemon now. In such a case it's probably wise to run sendmail -q every so often (fron cron) to push the queues.
  • If you want to get rid of SUID bit on sendmail binary - chmod 1777 /var/spool/mqueue and chmod 644 /etc/aliases.db and you may disable security warning as well.