web-dev-qa-db-ja.com

ホスト名-fと奇妙なDNS要求の場合は5秒

私の質問は、GentooLinuxシステムでのhostname-fの奇妙な動作に対処しています。

症状:

rt01 ~ # time hostname -f
rt01.domain.net

real    0m5.007s
user    0m0.001s
sys     0m0.000s

Straceを使用すると、次の手順が実行されていることがわかります。

  • /etc/Host.confを(おそらく)読んで、ホストルックアップを実行する順序を決定します
  • / etc/hostsを読んでください(私の意見ではこれで十分ですが、代わりに...)
  • /etc/resolv.confで指定されたDNSサーバーに接続します
  • / etc/hostsをもう一度読みます

そのマシンでiptablesを設定すると、DNSサーバーに接続できなくなります。したがって、この時点で(設計上)ブロックされています。私の期待は、このステップは次の構成では必要ないということです。

/ etc/Host.conf

# This keyword specifies how Host lookups are to be performed. It
# should be followed by one or more lookup methods, separated by
# commas.  Valid methods are bind, hosts, and nis.
#
order hosts, bind

/ etc/hosts

# IPv4 and IPv6 localhost aliases
127.0.0.1       rt01.domain.net rt01 localhost
<public ip>     rt01.domain.net rt01
::1             localhost

/ etc/conf.d/hostname

# Set to the hostname of this machine
hostname="rt01"

ホスト名-fがDNSサーバーに接続しようとする理由を誰かが私に説明できますか。/etc/hostsから提供された情報で十分だと思いました。

5
Christian Ehrig

DNSクエリが解決される順序は、/etc/nsswitch.confの内容に基づいています。具体的には、hostsの行のオプションの順序

たとえば、この行により、ローカルファイルをチェックする前にマシンがサーバーにクエリを実行します。

hosts:          dns files

マニュアルページ: http://man7.org/linux/man-pages/man5/nsswitch.conf.5.html

3
zymhan