Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Windows 綜合教學 >> 關於 Windows

Hosts 檔案作用與位置詳解:繞過 DNS 直接解析、跨平台路徑、修改生效指令

編輯:關於 Windows

hosts 檔案建立域名與 IP 的靜態對應,系統優先讀取 hosts 再查詢 DNS,可用於:

  • 封鎖網站(導向 127.0.0.1 或 0.0.0.0)。
  • 加速內部/特定域名解析。
  • 開發測試環境域名對應。
  • 惡意軟體竄改導向釣魚網站(需警惕)。

格式範例

127.0.0.1 google.com # 將 google.com 導向本機

各作業系統位置

作業系統路徑
Windows%SystemRoot%\system32\drivers\etc\hosts (如 C:\Windows\System32\drivers\etc\hosts)
Mac / iOS/etc/hosts
Symbian 6.1-9.0C:\system\data\hosts
Symbian 9.1+C:\private\10000882\hosts
Android/system/etc/hosts (需 Root)
Linux/etc/hosts

修改後生效指令

  • Windows: Win+R → cmd → ipconfig /flushdns
  • Linux (Systemd): sudo systemctl restart NetworkManager 或 sudo rcnscd restart
  • Mac OS X: sudo killall -HUP mDNSResponder
  • Android: 開啟/關閉飛航模式
  • 通用: 拔網線/斷網 → 重新連接

編輯建議使用 Notepad++ 等支援編碼/換行轉換的編輯器。謹慎修改,錯誤內容會導致網路異常。

Copyright © Windows教程網 All Rights Reserved