1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WindowsとLinuxにおける名前解決の仕組み

Posted at

はじめに

ネットワークの仕組みを学んでいると、ドメイン名をIPアドレスに変換するプロセスに socket ライブラリや OS の設定ファイルが関与することがわかります。しかし、Windows と Linux では設定ファイルの場所や動作が異なります。

この記事では、

  • WindowsとLinuxでの名前解決の違い
  • /etc/hostsC:\Windows\System32\drivers\etc\hosts の役割
  • nsswitch.confresolv.conf のWindowsにおける対応
  • Windows で DNS を設定する方法

を詳しく解説します!


WindowsとLinuxの名前解決の違い

機能 Linux/macOS Windows
ローカルの名前解決ファイル /etc/hosts C:\Windows\System32\drivers\etc\hosts
DNSの設定ファイル /etc/resolv.conf GUIの「ネットワークとインターネットの設定」から変更
優先順位を決める設定 /etc/nsswitch.conf Windows には直接対応する設定なし
ターミナルでの確認コマンド ping example.comnslookup example.com ping example.comnslookup example.com
設定ファイルの編集方法 nanovim で編集 notepad で管理者権限で編集

Windows では /etc/nsswitch.conf に相当する仕組みがなく、基本的に hosts ファイルよりも DNS サーバーが優先される場合があります。


Windows の hosts ファイルを編集する方法

Windows では /etc/hosts の代わりに C:\Windows\System32\drivers\etc\hosts を編集することで、特定のドメインの名前解決を制御できます。

hosts ファイルを開く

方法1: コマンドプロンプトで開く(おすすめ)

  1. Windowsキーを押して「cmd」と検索
  2. 「管理者として実行」 を選ぶ
  3. 以下のコマンドを実行:
    notepad C:\Windows\System32\drivers\etc\hosts
    
    これで hosts ファイルがメモ帳で開く。

方法2: エクスプローラーで開く

  1. C:\Windows\System32\drivers\etc\hosts に移動
  2. hosts ファイルを右クリック → 「管理者として実行」 でメモ帳で開く
  3. 必要な変更をして保存

② 例えばこんな設定を追加

93.184.216.34 example.com

これを追加すると、Windows では example.com へのアクセス時に DNS を使わず、直接 93.184.216.34 に接続する。

③ 動作確認

コマンドプロンプト(cmd)で ping してみる:

ping example.com

/etc/hosts に設定した IP アドレスに直接アクセスしているか確認!


Windows で /etc/resolv.conf に相当するものは?

Linux では DNS サーバーの設定を /etc/resolv.conf で管理しますが、Windows では GUI から設定するのが一般的です。

Windows でDNSサーバーを設定する方法

  1. 「ネットワークとインターネットの設定」を開く
  2. 「アダプターのオプションを変更する」をクリック
  3. 使用中のネットワーク(Wi-Fi または イーサネット)を右クリック → 「プロパティ」
  4. 「インターネット プロトコル バージョン4(TCP/IPv4)」を選択して「プロパティ」
  5. 「次のDNSサーバーのアドレスを使う」を選択して、DNSを手動設定
    • GoogleのDNS: 8.8.8.88.8.4.4
    • CloudflareのDNS: 1.1.1.11.0.0.1
    • OpenDNS: 208.67.222.222208.67.220.220

設定後に ipconfig /flushdns を実行すれば、変更が即時反映されます。


まとめ

  • Windows では /etc/hosts ではなく C:\Windows\System32\drivers\etc\hosts を編集する
  • Linux の /etc/resolv.conf の代わりに、Windows ではGUIでDNSを設定する
  • 名前解決の仕組みは似ているが、設定場所や動作が異なる
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?