標籤:
借用百度百科的解釋
Hosts是一個沒有副檔名的系統檔案,可以用記事本等工具開啟,其作用就是將一些常用的網址網域名稱與其對應的IP地址建立一個關聯“資料庫”,當使用者在瀏覽器中輸入一個需要登入的網址時,系統會首先自動從Hosts檔案中尋找對應的IP地址,一旦找到,系統會立即開啟對應網頁,如果沒有找到,則系統會再將網址提交DNS網域名稱解析伺服器進行IP地址的解析。
更詳細的說明:http://baike.baidu.com/link?url=uwQLcpconowLlQZII12bLU58-5uT_4qX5UOCz_Gr45ACo6CYyTCL4q-8VkZW4BxEsJzAVMBXyW6J8A2fEbwab_
檔案位置
C:\Windows\System32\Drivers\etc\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
檔案裡面已經說得很清晰了,主要的一點,添加ip跟網域名稱的時候至少要有一個空格隔開。
比如添加一個網域名稱,指向本機,個人習慣用tab分隔。
127.0.0.1sn.cn
測試是否生效,開啟命令列,ping
常見問題
1、沒有許可權修改hosts檔案:http://jingyan.baidu.com/article/ab69b270d963542ca6189f75.html
2、修改之後不生效,可能原因
1). dns緩衝沒重新整理
2). dnsclient服務影響,原因看windows自己的說明,關了就行了,再不行禁用。也不影響其它功能。比較快的啟動方式:運行services.msc
3). 360等安全軟體把hosts檔案鎖定了,在360面板的功能大全找到流量防火牆,修複它,這個問題印象很深刻,不解決的話前面的操作都沒用。
windows hosts 作用以及常見問題解決