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

Applies To
Windows 11 Windows 10

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

何謂 Hosts 檔案?

Hosts 檔案是作業系統用來對應容易理解的主機名稱 (例如 contoso.com) 到數字網際網路通訊協定 (IP) 位址的純文字系統檔案。 此對應可讓系統識別及尋找 IP 網路上的裝置,而且是作業系統 IP 實作的標準部分。

Hosts 檔案中的每個項目都會出現在自己的行中,並包含一個 IP 位址,後面接著一個或多個主機名稱,並以空格 (定位字元或空格) 分隔。 以井字號 (#) 開頭的行被視為註解,空白行會被忽略。

如果 Hosts 檔案從預設狀態進行修改,則可能會覆寫一般網路名稱解析,並造成連線問題。 將檔案重設為預設配置通常有助於解決存取網站或網路資源的問題

重設主機檔案

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

Windows 11

  1. 按下 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. 將 [另存新檔類型 ] 變更為 [所有檔案] (*.*) 。 hosts 檔案不能有副檔名。 

  5. 將檔案儲存到桌面並關閉 [記事本]。

  6. 搜尋 %WinDir%\System32\Drivers\Etc,然後選取 [ 檔案] 資料夾 圖示。
    注意:一般而言,此情況為 C:\Windows\System32\drivers\etc

  7. 用滑鼠右鍵按一下現有的 Hosts 檔案,選取 [重新命名],然後將檔案名稱變更為 “Hosts.old”。

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

Windows 10

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

  1. 按下 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. 將 [另存新檔類型 ] 變更為 [所有檔案] (*.*) 。 hosts 檔案不能有副檔名。 

  5. 將檔案儲存到桌面並關閉 [記事本]。

  6. 搜尋 %WinDir%\System32\Drivers\Etc,然後選取 [ 檔案] 資料夾 圖示。
    注意:一般而言,此情況為 C:\Windows\System32\drivers\etc

  7. 用滑鼠右鍵按一下現有的 Hosts 檔案,選取 [重新命名],然後將檔案名稱變更為 “Hosts.old”。

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