2010年3月10日

關於hosts檔


一般人是不會用到hosts檔。hosts檔要幹甚麼?
簡單的講,它的功能就如同DNS,當我們上網時,電腦在解析網域名稱(Domain Name)時,首先會先查詢自己電腦內 hosts 檔案內的對應資料,如果沒有查到,就會改採 DNS 查詢機制,查得該網域的 IP 位址。看看以下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:
10.0.0.1 a.com
192.168.0.1 b.com
127.0.0.1 c.com
根據上面hosts檔的內容,當我們打入網域
a.com會連結到IP 10.0.0.1
b.com會連結到IP 192.168.0.1
c.com會連結到IP 127.0.0.1

127.0.0.1就是自己的電腦的IP,就是localhost的IP。

hosts檔,很少人用,也很少人去做裏面的設定,hosts到底可以用在哪裡呢?
用在資安,過濾一些網站。諸如色情、釣魚、惡意、廣告網站,將這些網站導到所設定的IP或是本機,達到網路使用安全的目的,讓使用者不能上管制的網站。前陣子,上班玩開心網站,就可以用hosts檔來處理!
但是,問題是:
一、怎麼知道色情、釣魚、惡意、廣告網站的網域名稱(Domain Name)?
二、如果您是MIS,要如何把更新過的hosts檔,派送到各個電腦上?
三、如何讓一般使用者不去更改hosts檔案的設定內容?

最後告訴各位,這個檔案放在哪裡!
hosts檔放在C:\WINDOWS\SYSTEM32\DRIVERS\ETC目錄中,XP、 VISTA、 Windows 7都是一樣!

沒有留言: