在我的本地网络上,我连接了多台计算机。我通常不记得 IP 地址,也不在乎。今天早上,我去 RDP 在字段中输入“Sam”并按 Enter。它无法连接,所以我打开了一个命令提示符,看看我是否可以 ping 她的电脑并得到一些我以前从未见过的东西。
C:\Documents and Settings\wbeard52>ping sam
Pinging sam.WORKGROUP [67.215.65.132] with 32 bytes of data:
Reply from 67.215.65.132: bytes=32 time=51ms TTL=56
Run Code Online (Sandbox Code Playgroud)
显然,我在本地网络上有一台名为“sam”的计算机,我使用她的 IP 地址(不是此处列出的地址)将 RDP 连接到她的计算机。我在路由表中没有任何可以看到的内容。
wbeard52>route print
===========================================================================
Interface List
0x1 ........................... MS TCP Loopback interface
0x2 ...00 0e 35 a5 6f b2 ...... Intel(R) PRO/Wireless 2200BG Network Connection
- Packet Scheduler Miniport
===========================================================================
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 192.168.52.208 192.168.52.152 10
127.0.0.0 255.0.0.0 127.0.0.1 127.0.0.1 1
192.168.52.0 255.255.255.0 192.168.52.152 192.168.52.152 10
192.168.52.152 255.255.255.255 127.0.0.1 127.0.0.1 10
192.168.52.255 255.255.255.255 192.168.52.152 192.168.52.152 10
224.0.0.0 240.0.0.0 192.168.52.152 192.168.52.152 10
255.255.255.255 255.255.255.255 192.168.52.152 192.168.52.152 1
Default Gateway: 192.168.52.1
===========================================================================
Persistent Routes:
None
Run Code Online (Sandbox Code Playgroud)
什么会导致 ping 被发送到旧金山的 IP 地址?
我很确定@hyperslug 已经击中了它。当使用 OpenDNS 作为您的 DNS 提供商时,如果您尝试解析未知名称,他们将返回一个 IP 地址,将您的浏览器“重定向”到他们的品牌“结果”页面。使用 OpenDNS 时,您永远不会看到“404”页面。
如果您要使用 ISP 的 DNS 服务器并尝试使用PING sam,您会得到:
C:\>ping sam
Ping request could not find host sam. Please check the name and try again.
Run Code Online (Sandbox Code Playgroud)
要解决此问题(假设您想sam按名称解析而不必输入 IP 地址),您需要在HOSTS文件中为“sam”放置一个条目。
从你的路由表可以看出你在网络192.168.52.x上,你的电脑是192.168.52.152。我还可以看到您的默认网关是 192.168.52.1。你还没有提到IP地址sam是什么。出于本练习的目的,我们假设它sam是 192.168.52.201。
对于以下内容,我假设您的环境是 Windows。您将要编辑该文件%windir%\system32\drivers\etc\hosts.如果您从未使用过该hosts文件,您可能首先必须将其重命名%windir%\system32\drivers\etc\hosts.sam为%windir%\system32\drivers\etc\hosts.
在您喜欢的文本编辑器(例如记事本)中打开该文件,您将看到与以下内容非常相似的内容:
# Copyright (c) 1993-1999 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
127.0.0.1 localhost
Run Code Online (Sandbox Code Playgroud)
在 hosts 文件的末尾,添加一行:
192.168.52.201 sam
Run Code Online (Sandbox Code Playgroud)
保存文件,你就完成了。