Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

Win7 hosts 檔案位置與預設內容完整版:自訂域名解析、屏蔽廣告必備

編輯:Win7 系統應用技巧

想自訂域名指向 IP、屏蔽廣告/追蹤域名、測試本地網站?hosts 檔案是最直接的工具。本文提供 Win7 hosts 絕對路徑、預設內容完整備份、編輯權限取得、生效驗證全攻略,收藏即用。

一、什麼是 hosts 檔案?

無副檔名系統檔案,作為本地域名 → IP 對應表,優先順序高於 DNS 伺服器。系統解析域名時:
1. 檢查 DNS 快取 → 2. 讀取 hosts → 3. 查詢 DNS 伺服器。
若 hosts 含對應記錄 → 直接導向指定 IP;若 IP 為 0.0.0.0 或 127.0.0.1 → 達成屏蔽效果。

hosts 檔案說明

二、Win7 hosts 檔案位置

C:\Windows\System32\drivers\etc\hosts

三、預設內容完整版(可直接複製備份)

# 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

四、編輯 hosts 檔案(需管理員權限)

  1. Win → 搜尋 notepad → 右鍵「記事本」→「以系統管理員身分執行」。
  2. 記事本 →「檔案」→「開啟」→ 路徑貼上 C:\Windows\System32\drivers\etc → 右下角「文字文件」改「所有檔案」→ 選 hosts → 開啟。
  3. 在最後新增自訂對應(每行一條):
    127.0.0.1 ad.doubleclick.net
    127.0.0.1 analytics.google.com
    192.168.1.100 mysite.local
  4. 存檔(Ctrl+S)→ 關閉記事本。

五、立即生效驗證

  1. Win+R → cmd → ipconfig /flushdns 清除 DNS 快取。
  2. ping ad.doubleclick.net → 應回應 127.0.0.1。
  3. 瀏覽器開啟對應網站 → 廣告區塊空白/無法載入即生效。

六、常用 hosts 維護專案推薦

  • StevenBlack/hosts(GitHub):整合多個廣告/追蹤/惡意域名清單,定期更新。
  • racaljk/hosts:針對中國大陸網路環境優化,含 Google/學術/開發常用域名加速解析。
  • ADgk/hosts:精簡版,僅屏蔽核心廣告域名,體積小、相容性佳。

使用方式:下載專案 hosts 檔 → 以管理員權限覆蓋系統 hosts → ipconfig /flushdns。

七、權限問題排查

  • 存檔提示「存取被拒絕」 → 確認記事本以管理員執行、hosts 檔案屬性未勾選「唯讀」、防毒軟體未鎖定。
  • 修改後不生效 → 確認編碼為 ANSI/UTF-8 無 BOM、每行結尾無多餘空格、ipconfig /flushdns 已執行。

掌握 hosts 編輯,自訂解析、屏蔽廣告、本地測試全搞定,系統級網路控制權回到你手中!

Copyright © Windows教程網 All Rights Reserved