现在的位置: 首页 > 综合 > 正文

如何通过计算机名访问一台主机?

2012年09月08日 ⁄ 综合 ⁄ 共 1122字 ⁄ 字号 评论关闭
    这并不是一个新的文章,但前段时间由于工作需要遇到了这样的问题。
    我们架设了一个网站,由于某些原因,只能通过计算机名(主机名)访问这个站点,而不能通过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.*的主机了。

抱歉!评论已关闭.