什麼是Host檔案?
===================
簡單的答案就是: host檔案就像一個地址本. 當你在你的瀏覽器中鍵入一個網址的時候, host檔案會被查詢到, 看你是否已經為那個網站設定了IP地址. 如果你設定了, 那麼你的電腦會用這個IP去開啟網站. 如果沒有, 那麼電腦回去查詢你的internet service provider(ISP)的電腦去尋找IP地址. 多數的時候, 在host檔案中不會有那些IP. 所以多數時候, 電腦會去查詢ISP來獲得IP地址.
長一點的答案是: Windows和其他動作系統使用host檔案來將主機名稱與IP地址對應起來.
尋找與主機名稱對應的IP需要一系列的步驟:
先查詢你原生host檔案. host檔案會告訴你的電腦主機名稱對應的IP地址, 這樣你的電腦就會停止查詢, 直接開啟網站. 但是如果它沒找到, 它就會去詢問DNS伺服器(domain name server), 索要資訊.
Host檔案的位置
===================
Windows 95/98/Me
c:\windows\hosts
Windows NT/2000/XP Pro
c:\winnt\system32\drivers\etc\hosts
Windows XP Home / Windows 7/ Windows Server 2008
c:\windows\system32\drivers\etc\hosts
注意:
Host是檔案的名字而不是檔案夾的名字. 這個檔案沒有副檔名(比如說.exe, .txt, .doc等等)
如果你沒有host檔案, 你可以自己建立一個, 把它放到上面例舉的檔案夾中.
注意:
如果你發現你已經有了host檔案, 我推薦你把它備份一個, 拷貝到另外的一個硬碟分區上, 這樣你就可以恢複了.
Host檔案舉例
# 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 alternative80
http://accs-net.com/hosts/what_is_hosts.html
http://accs-net.com/hosts/how_to_use_hosts.html
http://en.wikipedia.org/wiki/Hosts_file