Windows 下編輯 hosts 檔案
阿新 • • 發佈:2019-01-13
hosts 檔案目錄:
C:\WINDOWS\system32\drivers\etc\hosts
- hosts是一個沒有副檔名的系統檔案,可以用記事本等工具開啟,其作用就是將一些常用的網址域名與其對應的IP地址建立一個關聯。
- 當用戶在瀏覽器中輸入一個需要登入的網址時,系統會首先自動從hosts檔案中尋找對應的IP地址,一旦找到,系統會立即開啟對應網頁,如果沒有找到,則系統會再將網址提交DNS域名解析伺服器進行IP地址的解析。
- hosts檔案裡包含對映IP 地址和host主機名的規定,每段只能包括一個對映關係,IP地址要放在每段的最前,而空格
後再寫上對映的主機名。
- 正常情況下,系統的hosts 檔案除了說明資訊外,只包含 “127.0.0.1 localhost” 這一段實際內容,如果出現其他的內容就表示被修改過了。如果hosts 檔案被修改了會有什麼後果暱?
有一種網頁劫持的方法就是惡意修改hosts 檔案,導致輸人某些正常網址時都會轉到廣告網站。要想解除這種劫持,修復Hosts 檔案即可。
- 另外,我們自己修改hosts檔案也可以起到加快網站域名解析、方便區域網使用者、遮蔽網站等作用。
比如訪問 github 網站速度比較慢,這時我們可以自己修改hosts檔案( ip 地址自己查詢),
52.74.223.119 github.com
覆蓋後,讓hosts生效
Windows
開始 -> 執行 -> 輸入cmd -> 在CMD視窗輸入 :
ipconfig /flushdns
要清空的話用記事本開啟他,只保留 127.0.0.1 localhost
其它全部刪除
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