來源:https://blog.csdn.net/double12754/article/details/88407132
1. 什么是host文件:
Hosts文件主要作用是定義IP地址和主機名的映射關系,是一個映射IP地址和主機名的規定。可以用文本文件打開!當用戶在瀏覽器中輸入一個需要登錄的網址時,系統會首先自動從Hosts文件中尋找對應的IP地址,一旦找到,瀏覽器會立即打開對應網頁,如果沒有找到,則瀏覽器會將網址提交遠程的DNS服務器進行IP地址解析。即:host文件可以提高我們加載網頁的速度。
2. 修改host文件有什么用?
比如我們要把www.xxx.com屏蔽掉,我們只需要這樣修改即可。
127.0.0.1 www.xxx.com #注釋
(注意:127.0.0.1和網址之間留下一個空格,網址和#注釋之間留下一個空格,還不懂可以參考電腦自帶屏蔽網址的格式)
另外需要注意的是注意,IP地址前面不要有空格,ip地址和域名之間,要有至少1個空格。修改后,一定要記得保存文件,如果裝有360安全衛士會提示是否禁止修改hosts文件,我們一定要選擇允許,否則會修改失敗。還有就是寫完一個網址一定要回車換行才會生效,一行只可以屏蔽一個網址,建議這樣修改:“ip地址+空格+域名+回車”來修改記錄!
3. 如何找到host文件?
同時按Windows鍵(就是電腦fn鍵和alt鍵之間的那個四方形)+R
然后在跳出來的運行窗輸入如下代碼:
c:\windows\system32\drivers\etc
第一個就是hosts文件,之后右鍵用記事本打開
在host文件最下方可以看到如下形式的幾行代碼:
4.如何修改host文件:
屏蔽網址:127.0.0.1和0.0.0.0之后的網址都是被屏蔽了的,https網址用0.0.0.0去屏蔽
加快瀏覽網址的速度:網址IP 網址
例:104.193.88.77 www.baidu.com
(IP地址請自行ping,因為我們的網絡不一樣)
如何ping網址呢?
同時按Windows+R,輸入cmd,確認;
出現一個黑色的界面,輸入ping www.baidu.com(ping和網址中間有一個空格)
# 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
127.0.0.1 local.id.seewo.com
127.0.0.1 genuine.microsoft.com
127.0.0.1 mpa.one.microsoft.com
127.0.0.1 sls.microsoft.com