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

修改 hosts 檔案實現本地域名解析:操作指南與五大應用場景

編輯:關於伺服器

操作步驟

  1. 以管理員身分開啟記事本。
  2. 開啟 C:\Windows\System32\drivers\etc\hosts。
  3. 新增一行:IP地址 域名 (中間至少一空格,IP 前無空格)。
    範例:112.124.39.29 www.45it.com
  4. 儲存檔案。

驗證生效

cmd → ping www.45it.com
# 回顯 IP 應為 hosts 中設定的 112.124.39.29

注意: Chrome 等瀏覽器有 DNS 快取,需關閉瀏覽器重開或輸入 chrome://net-internals/#dns 清除快取。

五大實用場景

場景說明範例
加速解析常用網站預先映射,省去 DNS 查詢192.168.1.10 portal.company.com
區域網別名給內網伺服器好記名稱10.0.0.5 svn
屏蔽惡意站點解析到 127.0.0.1 或 0.0.0.0127.0.0.1 ads.bad.com
強制指定解析測試新站未上線前僅本機可訪問203.0.113.5 new.example.com
繞過 DNS 劫持直接指向正確 IP8.8.8.8 dns.google

重要提醒

  • hosts 為靜態映射,目標 IP 變更需手動更新。
  • 不支援萬用字元 (如 *.example.com),需逐一列出。
  • 系統代理、VPN 可能繞過 hosts 解析。
Copyright © Windows教程網 All Rights Reserved