ドメイン名の名前解決に/etc/hostsを参照させる方法

  • 2013-05-11 修正

Postfixは送信メールのドメイン名からリレー先のIPアドレスを得る際、デフォルトでは/etc/hostsを一切参照せずいきなりDNSサーバにドメイン名についてのMXレコードを問い合わせてしまう。 したがって、/etc/hostsで設定している適当なホスト名を宛先としたメールを送信しようとすると、DNSサーバにそのホスト名についての問い合わせパケットが意図せず送られてしまう。

DNSサーバに問い合わせる前に/etc/hostsを参照させるようにするには、smtp_dns_support_levelパラメータをdisabledと指定すればよい。

# main.cf
smtp_dns_support_level = disabled

このように指定すると、Postfixは独自にDNSを引かなくなり、システム標準の方法でドメイン名の名前解決が行われるようになる。 たとえばLinuxの場合、/etc/nsswitch.confで次のように指定されていれば、まず最初に/etc/hostsが参照され、その次にDNSサーバへAレコードの問い合わせが行われる。

# /etc/nsswitch.conf
hosts:          files dns

ドキュメントでは次のように記載されている。 「"native" lookup」の詳細については、smtp_host_lookupの項に説明がある。

http://www.postfix.org/postconf.5.html#smtp_dns_support_level

smtp_dns_support_level (default: empty)
    Level of DNS support in the Postfix SMTP client. With "smtp_dns_support_level" left at its empty default value, the legacy "disable_dns_lookups" parameter controls whether DNS is enabled in the Postfix SMTP client, otherwise the legacy parameter is ignored.

    Specify one of the following:
    disabled
        Disable DNS lookups. No MX lookups are performed and hostname to address lookups are unconditionally "native". This setting is not appropriate for hosts that deliver mail to the public Internet. Some obsolete how-to documents recommend disabling DNS lookups in some configurations with content_filters. This is no longer required and strongly discouraged. 
    enabled
        Enable DNS lookups. Nexthop destination domains not enclosed in "[]" will be subject to MX lookups. If "dns" and "native" are included in the "smtp_host_lookup" parameter value, DNS will be queried first to resolve MX-host A records, followed by "native" lookups if no answer is found in DNS. 
    dnssec
        Enable DNSSEC lookups. The "dnssec" setting differs from the "enabled" setting above in the following ways:
            * Any MX lookups will set RES_USE_DNSSEC and RES_USE_EDNS0 to request DNSSEC-validated responses. If the MX response is DNSSEC-validated the corresponding hostnames are considered validated.
            * The address lookups of validated hostnames are also validated, (provided of course "smtp_host_lookup" includes "dns", see below).
            * Temporary failures in DNSSEC-enabled hostname-to-address resolution block any "native" lookups. Additional "native" lookups only happen when DNSSEC lookups hard-fail (NODATA or NXDOMAIN). 

http://www.postfix.org/postconf.5.html#smtp_host_lookup

smtp_host_lookup (default: dns)
    What mechanisms the Postfix SMTP client uses to look up a host's IP address. This parameter is ignored when DNS lookups are disabled (see: disable_dns_lookups and smtp_dns_support_level). The "dns" mechanism is always tried before "native" if both are listed.

    Specify one of the following:
    dns
        Hosts can be found in the DNS (preferred). 
    native
        Use the native naming service only (nsswitch.conf, or equivalent mechanism). 
    dns, native
        Use the native service for hosts not found in the DNS. 

    This feature is available in Postfix 2.1 and later.

Postfix 2.11より前のバージョンの場合は、disable_dns_lookups = yesとすれば同じことができる。 disable_dns_lookupsPostfix 2.11以降ではdeprecatedとなっている。