我正在我的电脑上测试一个应用程序,这个应用程序连接到各种服务器,所以我需要在我的机器上模拟它。
如何将主机名映射到 127.0.0.1?
localhost
已经指的是 127.0.0.1,但我怎样才能添加更多内容,例如server-1
和server-2
到 127.0.0.1?
我在使用 Windows 7。
谢谢
答案1
只需编辑您的hosts
文件并使用其指向 127.0.0.1 或您机器的本地 IP 地址。
该文件通常位于:/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
192.168.202.32 feng
192.168.202.241 helpdesk
192.168.202.241 wiki
192.168.202.241 rs
192.168.202.241 precurio
192.168.202.241 zendto