linux における名前解決 ( /etc/hosts 関連)
linux の名前解決に関して調べたので備忘録として
結論
ここに全て書いてある
簡単に書くと
/etc/nsswitch.conf
という設定ファイルがあり、その中に hosts
を設定する部分がある。
以下該当の行のみ抜粋。
# ホストの名前解決の為にまずはファイルを参照し、失敗したら DNS に問い合わせをする。
hosts: files dns
ファイル
ファイルは /etc/hosts
ファイル
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
上記の記述で、 localhost という名前は、 127.0.0.1 というIPアドレスに変換される。
ファイル内に記述がない場合は、DNS に問い合わせする。
DNS
DNSとは?
IPアドレスとドメイン名の紐付けをしまっせシステムのこと
権威DNSサーバーとか、キャッシュサーバーとかあるので気になる人は調べてみてください。
どのDNSサーバーに問い合わせをするか決めるのが、/etc/resolv.conf
ファイル
#
# macOS Notice
#
# This file is not consulted for DNS hostname resolution, address
# resolution, or the DNS query routing mechanism used by most
# processes on this system.
#
# To view the DNS configuration used by this system, use:
# scutil --dns
#
# SEE ALSO
# dns-sd(1), scutil(8)
#
# This file is automatically generated.
#
nameserver 8.8.8.8 # GoogleのパブリックDNS
nameserver 8.8.4.4 # GoogleのパブリックDNS
nameserver 1.1.1.1 # Cloudflare(クラウドフレア)がAPNICと提携して維持・運営を行っている
nameserver 1.0.0.1 # Cloudflare(クラウドフレア)がAPNICと提携して維持・運営を行っている
nsswitch
は多分 name server switch
で、名前解決するネームサーバーを切り替える(switch)設定ファイルみたいな位置付けかと思います。(多分)
ちなみに
windows でも同じように設定ができるようです。
mac は hosts
ファイルや resolv.conf
はあるが、 nsswitch.conf
の役割をしているものはなさそう、、、(調べたけど見つからない)
まとめ
どうやって名前解決しているかわかってよかった!
Author And Source
この問題について(linux における名前解決 ( /etc/hosts 関連)), 我々は、より多くの情報をここで見つけました https://qiita.com/arinco_/items/f3bd3a75baf7b46811fb著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .