Windows系統本地域名配置文件hosts位於目錄C:\Windows\System32\drivers\etc
中,其內容大致如下所示:
# 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
這裏,我們向其中添加如下一行記錄,代表將域名vm200.lan指向IP地址223.6.6.6,即
# 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
223.6.6.6 vm200.lan
通常情況下,系統盤(C:)中的文件對於普通用戶僅僅有隻讀權限,本地域名配置文件hosts即是如此,如果要編輯文件內容,需要修改文件的權限,以hosts爲例,修改步驟如下圖所示。
修改完成後,可以打開命名行終端用ping命令驗證結果,即
Microsoft Windows [Version 10.0.18362.30]
(c) 2019 Microsoft Corporation. All rights reserved.
C:\Users\lwk>ping vm200.lan
Pinging vm200.lan [223.6.6.6] with 32 bytes of data:
Reply from 223.6.6.6: bytes=32 time=10ms TTL=63
Reply from 223.6.6.6: bytes=32 time=8ms TTL=63
Reply from 223.6.6.6: bytes=32 time=8ms TTL=63
Reply from 223.6.6.6: bytes=32 time=12ms TTL=63
Ping statistics for 223.6.6.6:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 8ms, Maximum = 12ms, Average = 9ms
C:\Users\lwk>
如圖所示,這裏的修改就生效了。