這並不是一個新的文章,但前段時間由於工作需要遇到了這樣的問題。
我們架設了一個網站,由於某些原因,只能通過電腦名稱(主機名稱)訪問這個網站,而不能通過IP地址訪問。
而有些時候,我們區域網路內的使用者是可以訪問的,但又有一部分使用者不能訪問。為此,我查閱了一些資料,發現了這個解決辦法。原來在C:\windows\system32\drivers\etc目錄下,有一個名為hosts的檔案。其內容如下: 1# Copyright (c) 1993-1999 Microsoft Corp.
2#
3# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
4#
5# This file contains the mappings of IP addresses to host names. Each
6# entry should be kept on an individual line. The IP address should
7# be placed in the first column followed by the corresponding host name.
8# The IP address and the host name should be separated by at least one
9# space.
10#
11# Additionally, comments (such as these) may be inserted on individual
12# lines or following the machine name denoted by a '#' symbol.
13#
14# For example:
15#
16# 102.54.94.97 rhino.acme.com # source server
17# 38.25.63.10 x.acme.com # x client host
18
19127.0.0.1 localhost
我們看到,在最後一行的127.0.0.1 localhost. 前面是IP地址,後面就是對應這個IP的主機名稱。因此,現在我們訪問127.0.0.1和localhost都是訪問的本地主機。
現在,我們在之後增加一行:1211.143.112.* techserver
現在我們就可以通過主機名稱techserver訪問IP地址為211.143.112.*的主機了。