如何在不使用 DHCP 服务器的情况下使用自动 TCP/IP 寻址How to use automatic TCP/IP addressing without a DHCP server

本文介绍如何使用自动传输控制协议/internet 协议 (TCP/IP) 寻址,而无需使用动态主机配置协议 (DHCP) 服务器在网络上提供。This article describes how to use automatic Transmission Control Protocol/Internet Protocol (TCP/IP) addressing without a Dynamic Host Configuration Protocol (DHCP) server being present on the network. 本文 "应用于" 部分中列出的操作系统版本具有一项称为自动专用 IP 寻址 (APIPA) 的功能。The operating system versions listed in the "Applies to" section of this article have a feature called Automatic Private IP Addressing (APIPA). 使用此功能,Windows 计算机可以在 DHCP 服务器不可用或网络上不存在时,向其分配 Internet 协议 (IP) 地址。With this feature, a Windows computer can assign itself an Internet Protocol (IP) address in the event that a DHCP server is not available or does not exist on the network. 此功能使配置和支持小型局域网 (LAN) 运行 TCP/IP 的难度更小。This feature makes configuring and supporting a small Local Area Network (LAN) running TCP/IP less difficult.

更多信息More Information

重要

请认真遵循本部分所述的步骤。Follow the steps in this section carefully. 如果注册表修改不正确,可能会发生严重问题。Serious problems might occur if you modify the registry incorrectly. 在修改注册表之前,请备份注册表,以便在出现问题时可以还原。Before you modify it, back up the registry for restoration in case problems occur.

如果 DHCP 服务器不可用,则配置为使用 DHCP 的基于 Windows 的计算机可以自动为其分配 Internet 协议 (IP) 地址。A Windows-based computer that is configured to use DHCP can automatically assign itself an Internet Protocol (IP) address if a DHCP server is not available. 例如,如果 DHCP 服务器暂时关闭以进行维护,则可能会在没有 DHCP 服务器的网络上或在网络上发生这种情况。For example, this could occur on a network without a DHCP server, or on a network if a DHCP server is temporarily down for maintenance.

Internet 编号分配机构 (IANA) 为自动专用 IP 寻址保留169.254.255.255。The Internet Assigned Numbers Authority (IANA) has reserved 169.254.0.0-169.254.255.255 for Automatic Private IP Addressing. 因此,APIPA 提供的地址不能与可路由地址冲突。As a result, APIPA provides an address that is guaranteed not to conflict with routable addresses.

为网络适配器分配 IP 地址后,计算机可以使用 TCP/IP 与连接到同一 LAN 并且也配置为 APIPA 的任何其他计算机进行通信,或将 IP 地址手动设置为 169.254. (其中,x 是客户端的唯一标识符) 地址范围,子网掩码为255.255.0.0。After the network adapter has been assigned an IP address, the computer can use TCP/IP to communicate with any other computer that is connected to the same LAN and that is also configured for APIPA or has the IP address manually set to the 169.254.x.y (where x.y is the client's unique identifier) address range with a subnet mask of 255.255.0.0. 请注意,计算机无法与其他子网上的计算机或不使用自动专用 IP 寻址的计算机进行通信。Note that the computer cannot communicate with computers on other subnets, or with computers that do not use automatic private IP addressing. 默认情况下启用自动专用 IP 寻址。Automatic private IP addressing is enabled by default.

在以下任一情况下,你可能想要将其禁用:You may want to disable it in any of the following cases:

  • 网络使用路由器。Your network uses routers.

  • 你的网络已连接到 Internet,无 NAT 或代理服务器。Your network is connected to the Internet without a NAT or proxy server.

除非已禁用与 DHCP 相关的消息,否则 DHCP 消息会在 DHCP 寻址和自动专用 IP 寻址之间进行更改时向你提供通知。Unless you have disabled DHCP-related messages, DHCP messages provide you with notification when you change between DHCP addressing and automatic private IP addressing. 如果意外禁用了 DHCP 消息传递,则可以通过将以下注册表项中的 PopupFlag 值的值从00改为01来重新启用 DHCP 消息:HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\DHCPIf DHCP messaging is accidentally disabled, you can turn the DHCP messages back on by changing the value of the PopupFlag value in the following registry key from 00 to 01: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\DHCP

请注意,必须重新启动计算机才能使更改生效。Note that you must restart your computer for the change to take effect. 你还可以使用 Windows Millennium Edition、Windows 98 或 Windows 98 Second 版中的 Winipcfg 工具来确定你的计算机是否在使用 APIPA:You can also determine whether your computer is using APIPA by using the Winipcfg tool in Windows Millennium Edition, Windows 98, or Windows 98 Second Edition:

单击 "开始",再单击 "运行",键入 "winipcfg" (不带引号) ,然后单击 "确定"。Click Start , click Run , type "winipcfg" (without the quotation marks), and then click OK . 单击 "详细信息"。Click More Info . 如果 IP 自动配置地址框包含 169.254. 范围内的 IP 地址,则会启用自动专用 IP 寻址。If the IP Autoconfiguration Address box contains an IP address within the 169.254.x.x range, Automatic Private IP Addressing is enabled. 如果 "IP 地址" 框存在,则当前未启用自动专用 IP 寻址。If the IP Address box exists, automatic private IP addressing is not currently enabled. 对于 Windows 2000、Windows XP 或 Windows Server 2003,你可以在命令提示符处使用 IPconfig 命令确定你的计算机是否在使用 APIPA:For Windows 2000, Windows XP, or Windows Server 2003, you can determine whether your computer is using APIPA by using the IPconfig command at a command prompt:

单击 "开始",再单击 "运行",键入 "cmd" (没有引号) ,然后单击 "确定" 以打开 MS-DOS 命令行窗口。Click Start , click Run , type "cmd" (without the quotation marks), and then click OK to open a MS-DOS command line window. 键入 "ipconfig/all" (没有引号) ,然后按 ENTER 键。Type "ipconfig /all" (without the quotation marks), and then hit the ENTER key. 如果启用了 "自动配置" 行显示 "是",并且 "自动配置 IP 地址" 为 169.254. (其中,x 是客户端的唯一标识符) ,则计算机使用 APIPA。If the 'Autoconfiguration Enabled' line says "Yes", and the 'Autoconfiguration IP Address' is 169.254.x.y (where x.y is the client's unique identifier), then the computer is using APIPA. 如果 "已启用自动配置" 行显示 "否",则表示计算机当前未使用 APIPA。If the 'Autoconfiguration Enabled' line says "No", then the computer is not currently using APIPA. 可以通过使用以下方法之一来禁用自动专用 IP 寻址。You can disable automatic private IP addressing by using either of the following methods.

你可以手动配置 TCP/IP 信息,这将完全禁用 DHCP。You can configure the TCP/IP information manually, which disables DHCP altogether. 可以通过编辑注册表来禁用自动专用 IP 寻址 (但不能禁用 DHCP) 。You can disable automatic private IP addressing (but not DHCP) by editing the registry. 为此,可以将值为0x0 的 "IPAutoconfigurationEnabled" DWORD 注册表项添加到 Windows Millennium Edition、Windows98 或 Windows 98 Second Edition 的以下注册表项:HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\DHCPYou can do so by adding the "IPAutoconfigurationEnabled" DWORD registry entry with a value of 0x0 to the following registry key for Windows Millennium Edition, Windows98, or Windows 98 Second Edition: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\DHCP

对于 Windows 2000、Windows XP 和 Windows Server 2003,可以通过将值为0x0 的 "IPAutoconfigurationEnabled" DWORD 注册表项添加到以下注册表项来禁用 APIPA:HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\<Adapter GUID>For Windows 2000, Windows XP, and Windows Server 2003, APIPA can be disabled by adding the "IPAutoconfigurationEnabled" DWORD registry entry with a value of 0x0 to the following registry key: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\<Adapter GUID>

备注

适配器 guid子项是计算机 LAN 适配器 (GUID) 的全局唯一标识符。The Adapter GUID subkey is a globally unique identifier (GUID) for the computer's LAN adapter.

将 IPAutoconfigurationEnabled DWORD 条目的值指定为1将启用 APIPA,这是从注册表中省略此值时的默认状态。Specifying a value of 1 for IPAutoconfigurationEnabled DWORD entry will enable APIPA, which is the default state when this value is omitted from the registry.

APIPA 可能有用的示例Examples of Where APIPA may be useful

示例1:没有以前的 IP 地址,也没有 DHCP 服务器Example 1: No Previous IP Address and no DHCP Server

如果基于 Windows 的计算机 (配置为 DHCP) 正在初始化,则会广播三个或更多 "发现" 消息。When your Windows-based computer (configured for DHCP) is initializing, it broadcasts three or more "discover" messages. 如果在广播多个发现消息后,DHCP 服务器不响应,则 Windows 计算机会为自身分配类 B (APIPA) 地址。If a DHCP server does not respond after several discover messages are broadcast, the Windows computer assigns itself a Class B (APIPA) address. 然后,Windows 计算机将向计算机的用户显示一条错误消息, (在过去的) 中,该计算机还从未向 DHCP 服务器分配 IP 地址。Then the Windows computer will display an error message to the user of the computer (providing it has never been assigned an IP address from a DHCP server in the past). Windows 计算机每隔三分钟发送一次发现消息,尝试建立与 DHCP 服务器的通信。The Windows computer will then send out a Discover message every three minutes in an attempt to establish communications with a DHCP server.

示例2:以前的 IP 地址,没有 DHCP 服务器Example 2: Previous IP Address and no DHCP Server

计算机检查 DHCP 服务器,如果找不到,则尝试联系默认网关。The computer checks for the DHCP server and if none are found, an attempt is made to contact the default gateway. 如果默认网关应答,则 Windows 计算机将保留以前租用的 IP 地址。If the default gateway replies, then the Windows computer retains the previously-leased IP address. 但是,如果计算机没有收到来自默认网关的响应,或者未分配任何响应,则它将使用自动专用 IP 寻址功能为自己分配 IP 地址。However, if the computer does not receive a response from the default gateway or if none are assigned, then it uses the automatic private IP addressing feature to assign itself an IP address. 将向用户显示一条错误消息,并每隔3分钟传输一次发现消息。An error message is presented to the user and discover messages are transmitted every 3 minutes. DHCP 服务器进入行后,会生成一条消息,指出已与 DHCP 服务器重新建立通信。Once a DHCP server comes on line, a message is generated stating communications have been re-established with a DHCP Server.

示例3:租约过期且无 DHCP 服务器Example 3: Lease Expires and no DHCP Server

基于 Windows 的计算机尝试重新建立 IP 地址的租约。The Windows-based computer tries to re-establish the lease of the IP address. 如果 Windows 计算机没有找到 DCHP 服务器,则会在生成错误消息之后为自己分配 IP 地址。If the Windows computer does not find a DCHP server, it assigns itself an IP address after generating an error message. 然后,计算机将广播四个发现消息,每5分钟一次,它会重复整个过程,直到 DHCP 服务器联机。The computer then broadcasts four discover messages, and after every 5 minutes it repeats the whole procedure until a DHCP server comes on line. 随后会生成一条消息,指出已与 DHCP 服务器重新建立通信。A message is then generated stating that communications have been re-established with the DHCP Server.