天天看點

Windows 下編輯 hosts 檔案

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
           

繼續閱讀