🏘️
Windows内の名前解決の経路まとめ
トラブルシューティングのためのインターネット接続の基礎知識
前提
全体像
デフォルトゲートウェイ (デフォルトGW)
LAN内外の境界線に配置される出入口のこと
ローカルネットワークとインターネット間の接続を仲介する
一般家庭のNWでは、WifiルータがデフォルトGWになっていることが多い
hostsファイル
Windowsに搭載されているDNS以外の名前解決の仕組み
WindowsではDNSサーバへの問い合わせ前にhostsの内容を確認し、対応するドメインがhostsにあったらDNSを使用しないで名前解決が行われる
以下に配置されている
C:\Windows\System32\drivers\etc\hosts
$env:SystemRoot\System32\drivers\etc\hosts
hostsの中身
DockerDesktop関連は筆者環境独自のもの
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
# Added by Docker Desktop
192.168.86.57 host.docker.internal
192.168.86.57 gateway.docker.internal
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section
hosts和訳
# Copyright (c) 1993-2009 Microsoft Corp.
#
# これは、Microsoft TCP/IP for Windows によって使用されるサンプルの HOSTS ファイルです。
#
# このファイルには、IP アドレスとホスト名の対応が記述されています。
# 各エントリは 1 行ごとに記述してください。
# IP アドレスは行の最初の列に置き、続けて対応するホスト名を記述します。
# IP アドレスとホスト名の間は、少なくとも 1 つのスペースで区切ってください。
#
# また、コメント(このような行)は個別の行として挿入することも、
# マシン名の後に '#' 記号を使って記述することもできます。
#
# 例:
#
# 102.54.94.97 rhino.acme.com # ソースサーバー
# 38.25.63.10 x.acme.com # x クライアントホスト
# localhost の名前解決は DNS によって処理されます。
# 127.0.0.1 localhost
# ::1 localhost
# Added by Docker Desktop
192.168.86.57 host.docker.internal
192.168.86.57 gateway.docker.internal
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section
NetBIOS (Network Basic I/O System)
色々謂れのあるNetBIOS
LAN内で名前解決を行うための仕組み
hostsのようにlmhostsファイルでNetBIOSとIPアドレスの対応が行われる
以下に配置されている
C:\Windows\System32\drivers\etc\lmhosts
$env:SystemRoot\System32\drivers\etc\lmhosts
lmhosts中身
# Copyright (c) 1993-1999 Microsoft Corp.
#
# This is a sample LMHOSTS file used by the Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to computernames
# (NetBIOS) names. Each entry should be kept on an individual line.
# The IP address should be placed in the first column followed by the
# corresponding computername. The address and the computername
# should be separated by at least one space or tab. The "#" character
# is generally used to denote the start of a comment (see the exceptions
# below).
#
# This file is compatible with Microsoft LAN Manager 2.x TCP/IP lmhosts
# files and offers the following extensions:
#
# #PRE
# #DOM:<domain>
# #INCLUDE <filename>
# #BEGIN_ALTERNATE
# #END_ALTERNATE
# \0xnn (non-printing character support)
#
# Following any entry in the file with the characters "#PRE" will cause
# the entry to be preloaded into the name cache. By default, entries are
# not preloaded, but are parsed only after dynamic name resolution fails.
#
# Following an entry with the "#DOM:<domain>" tag will associate the
# entry with the domain specified by <domain>. This affects how the
# browser and logon services behave in TCP/IP environments. To preload
# the host name associated with #DOM entry, it is necessary to also add a
# #PRE to the line. The <domain> is always preloaded although it will not
# be shown when the name cache is viewed.
#
# Specifying "#INCLUDE <filename>" will force the RFC NetBIOS (NBT)
# software to seek the specified <filename> and parse it as if it were
# local. <filename> is generally a UNC-based name, allowing a
# centralized lmhosts file to be maintained on a server.
# It is ALWAYS necessary to provide a mapping for the IP address of the
# server prior to the #INCLUDE. This mapping must use the #PRE directive.
# In addtion the share "public" in the example below must be in the
# LanManServer list of "NullSessionShares" in order for client machines to
# be able to read the lmhosts file successfully. This key is under
# \machine\system\currentcontrolset\services\lanmanserver\parameters\nullsessionshares
# in the registry. Simply add "public" to the list found there.
#
# The #BEGIN_ and #END_ALTERNATE keywords allow multiple #INCLUDE
# statements to be grouped together. Any single successful include
# will cause the group to succeed.
#
# Finally, non-printing characters can be embedded in mappings by
# first surrounding the NetBIOS name in quotations, then using the
# \0xnn notation to specify a hex value for a non-printing character.
#
# The following example illustrates all of these extensions:
#
# 102.54.94.97 rhino #PRE #DOM:networking #net group's DC
# 102.54.94.102 "appname \0x14" #special app server
# 102.54.94.123 popular #PRE #source server
# 102.54.94.117 localsrv #PRE #needed for the include
#
# #BEGIN_ALTERNATE
# #INCLUDE \\localsrv\public\lmhosts
# #INCLUDE \\rhino\public\lmhosts
# #END_ALTERNATE
#
# In the above example, the "appname" server contains a special
# character in its name, the "popular" and "localsrv" server names are
# preloaded, and the "rhino" server name is specified so it can be used
# to later #INCLUDE a centrally maintained lmhosts file if the "localsrv"
# system is unavailable.
#
# Note that the whole file is parsed including comments on each lookup,
# so keeping the number of comments to a minimum will improve performance.
# Therefore it is not advisable to simply add lmhosts file entries onto the
# end of this file.
lmhosts中身の和訳
# Copyright (c) 1993-1999 Microsoft Corp.
#
# これは、Microsoft TCP/IP for Windows によって使用される LMHOSTS ファイルのサンプルです。
#
# このファイルには、IP アドレスとコンピューター名(NetBIOS名)の対応関係が記述されています。
# 各エントリは 1 行ごとに記述してください。
# IP アドレスは行の最初の列に配置し、それに続けて対応するコンピューター名を記述します。
# アドレスとコンピューター名の間には、少なくとも1つのスペースまたはタブで区切る必要があります。
# 「#」記号は、通常コメントの開始を示すために使用されます(例外については下記を参照)。
#
# このファイルは Microsoft LAN Manager 2.x の TCP/IP lmhosts ファイルと互換性があり、次の拡張機能を提供します:
#
# #PRE
# #DOM:<domain>
# #INCLUDE <filename>
# #BEGIN_ALTERNATE
# #END_ALTERNATE
# \0xnn(表示されない文字のサポート)
#
# ファイル内の任意のエントリの後ろに「#PRE」を付けると、
# そのエントリは名前キャッシュに事前読み込みされます。
# 通常、エントリは事前読み込みされず、動的な名前解決が失敗した後にのみ解析されます。
#
# エントリの後ろに「#DOM:<domain>」タグを付けると、
# 指定された <domain> にそのエントリを関連付けることができます。
# これは、TCP/IP 環境におけるブラウザーサービスやログオンサービスの動作に影響します。
# #DOM エントリに関連付けられたホスト名を事前読み込みするには、
# 同じ行に #PRE を追加する必要があります。
# <domain> 自体は常に事前読み込みされますが、名前キャッシュを表示しても見えません。
#
# 「#INCLUDE <filename>」を指定すると、RFC NetBIOS(NBT)ソフトウェアが
# 指定された <filename> を探し、それをローカルファイルのように解析します。
# <filename> は通常、UNC 形式の名前で、サーバー上に集中管理された lmhosts ファイルを参照することができます。
# #INCLUDE の前に、サーバーの IP アドレスに対するマッピングを提供する必要があります。
# このマッピングには必ず #PRE ディレクティブを使わなければなりません。
#
# また、下記の例で使われている "public" という共有フォルダーは、
# クライアントマシンが lmhosts ファイルを正常に読み取れるようにするために、
# レジストリの以下のキーにある LanManServer の「NullSessionShares」リストに
# 登録されている必要があります:
# \machine\system\currentcontrolset\services\lanmanserver\parameters\nullsessionshares
# そこに「public」を追加してください。
#
# #BEGIN_ および #END_ALTERNATE キーワードを使うと、
# 複数の #INCLUDE ステートメントをグループ化できます。
# どれか一つの include が成功すれば、そのグループは成功とみなされます。
#
# 最後に、非表示文字をマッピングに含めたい場合は、
# NetBIOS名を引用符(")で囲み、\0xnn の表記で非表示文字の 16進数値を指定してください。
#
# 以下の例では、これらすべての拡張機能を示しています:
#
# 102.54.94.97 rhino #PRE #DOM:networking #ネットグループのドメインコントローラー
# 102.54.94.102 "appname \0x14" #特殊なアプリサーバー
# 102.54.94.123 popular #PRE #ソースサーバー
# 102.54.94.117 localsrv #PRE #INCLUDE 用に必要
#
# #BEGIN_ALTERNATE
# #INCLUDE \\localsrv\public\lmhosts
# #INCLUDE \\rhino\public\lmhosts
# #END_ALTERNATE
#
# 上記の例では、「appname」サーバー名に特殊文字が含まれており、
# 「popular」と「localsrv」のサーバー名は事前読み込みされます。
# そして「rhino」サーバー名は、「localsrv」システムが使えない場合に
# 中央管理された lmhosts ファイルを読み込むために指定されています。
#
# 注意:ファイル内の各検索時にコメントを含めて全体が解析されるため、
# コメントの数を最小限にすることでパフォーマンスが向上します。
# したがって、lmhosts のエントリを単純にこのファイルの末尾に追加するのは避けたほうがよいです。
# end of this file.
WindowsにおけるDHCP設定手順
有効にすることを強く推奨
Windows11での有効化手順
- コマンドを実行し、NW一覧を開く
ncpa.cpl
- 「状態」または「イーサネット」/「Wi-Fi」> 「アダプターのオプションを変更する」をクリック
- 設定したいネットワークアダプターを右クリックし、「プロパティ」をクリック
- 有線接続⇒ イーサネット
- 無線接続⇒ Wi-Fi
- 「ネットワークタブ」 > 「TCP/IPv4」を選択し、「プロパティ」をクリック
- 「全般」タブ > 「IP アドレスを自動的に取得する」と「DNS サーバーのアドレスを自動的に取得する」にチェックを入れてOK
- 手動にする場合 (DNSの競合が発生し独自設定が必要が場合など)
- IP アドレス⇒プライベートIPアドレス。他機器と重複しないように設定する。
- サブネットマスク⇒ 255.255.255.0
- デフォルトゲートウェイ⇒ ルーターの IP アドレスなど
- 優先/代替 DNSサーバ⇒ Google Public DNS の「8.8.8.8」などパブリックDNSのパブリックIPを指定する
- コマンドを実行し、テスト接続
curl google.co.jp
トラブルシューティング
hostsとDHCPの設定を確認したうえで解消しなかったら以下の手順
IPアドレスの確認
コマンドを実行しIPアドレスを確認する ipconfig /all
下記を確認する
- IPv4 アドレス:
169.254.x.x
(APIPA アドレス)や0.0.0.0
になっている場合、DHCP サーバーから IP アドレスを正しく取得できていない可能性が高い - サブネットマスク:
255.255.255.0
以外が表示されたら注意 - デフォルトゲートウェイ: LAN内のルーターのIPアドレスと不一致なら注意。NWアダプターのドライバーに問題 or Windows のネットワーク設定が誤っている
コマンドを実行し、テスト接続 curl google.co.jp
感想
lmhosts中身初めてしっかり読んでほえ~ってなった
Discussion
netbiosタグ最古記事になって草