如何將 Hosts 檔案重設回預設值

套用到
Windows 11 Windows 10

如果你遇到網路或網站連線問題,Hosts 檔案可能是問題的一部分。 本文說明 Hosts 檔案是什麼、運作方式,以及為什麼將它重設到預設狀態能解決常見連線問題。

何謂 Hosts 檔案?

Hosts 檔案是作業系統用來將友善主機名稱 (如 contoso.com) 映射到數值網際網路協定 (IP) 位址的純文字系統檔案。 這種映射讓系統能夠識別並定位 IP 網路上的裝置,是作業系統 IP 實作的標準部分。

Hosts 檔案中的每個項目都出現在獨立行中,包含一個 IP 位址後接一個或多個主機名稱,並以空白區隔 (分頁或空格) 。 以雜湊字元 (#) 開頭的行被視為註解,空白行則被忽略。

如果 Hosts 檔案被修改為預設狀態,可能會覆蓋正常的網路名稱解析,導致連線問題。 將檔案重設為預設設定,通常有助於解決存取網站或網路資源的問題

重設你的主機檔案

如果要將 Hosts 檔案重設回預設值,請根據您的作業系統執行下列步驟:

Windows 11

  1. 按下 WindowsLogo 視窗鍵,輸入 Notepad,然後選擇 記事本 應用程式圖示。

  2. 複製下列文字,然後將文字貼至檔案:

    # 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
    
  3. 檔案 選單中,選擇 另存為 ,並在 檔案名稱 框中輸入「hosts」 (,並) 引號。

  4. 另存為檔案類型 改為 (*.*) 。 主機的檔案不能有副檔名。 

  5. 把檔案存 到桌面,然後關閉記事本。

  6. 搜尋 %WinDir%\System32\Drivers\Etc,然後選擇 檔案資料夾 圖示。
    注意:通常這是 C:\Windows\System32\drivers\etc

  7. 右鍵點擊現有的 Hosts 檔案,選擇 Rename,然後將檔名改為「Hosts.old」。

  8. 將你從桌面建立的 Hosts 檔案複製或移動到 %WinDir%\System32\Drivers\Etc 資料夾。 如果提示您輸入系統管理員密碼,請選取 「繼續」

Windows 10

如果要將 Hosts 檔案重設回預設值,請依照下列步驟執行:

  1. 按下 Windows 標誌 的 Windows 鍵,輸入 Notepad,然後選擇 記事本 系統圖示。

  2. 複製下列文字,然後將文字貼至檔案:

    # 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
    
  3. 檔案 選單中,選擇 另存為 ,並在 檔案名稱 框中輸入「hosts」 (,並) 引號。

  4. 另存為檔案類型 改為 (*.*) 。 主機的檔案不能有副檔名。 

  5. 把檔案存 到桌面,然後關閉記事本。

  6. 搜尋 %WinDir%\System32\Drivers\Etc,然後選擇 檔案資料夾 圖示。
    注意:通常這是 C:\Windows\System32\drivers\etc

  7. 右鍵點擊現有的 Hosts 檔案,選擇 Rename,然後將檔名改為「Hosts.old」。

  8. 將你從桌面建立的 Hosts 檔案複製或移動到 %WinDir%\System32\Drivers\Etc 資料夾。 如果提示您輸入系統管理員密碼,請選取 「繼續」