如何在沒有 DHCP 伺服器的情況下使用自動 TCP/IP 定址How to use automatic TCP/IP addressing without a DHCP server

本文說明如何使用自動傳輸控制通訊協定/網際網路通訊協定 (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). 使用這項功能時,如果 DHCP 伺服器無法使用或不存在於網路上,Windows 電腦就可以將網際網路通訊協定指派 (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. 這項功能可讓您在執行 TCP/IP 的 (LAN) 設定和支援較不困難的區域網路。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 的 Windows 電腦,可以在 DHCP 伺服器無法使用時,自動將網際網路通訊協定指派 (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.

網際網路指派的號碼授權單位 (IANA) 具有自動私人 IP 位址的保留169.254.255.255。The Internet Assigned Numbers Authority (IANA) has reserved 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 的電腦通訊,也可以將 IP 位址手動設定為 (169.254.,其中,x. y 是用戶端唯一識別碼) 位址範圍,子網路遮罩為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 請注意,電腦無法與其他子網上的電腦或未使用自動私人 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.

  • 您的網路已連線到網際網路,但沒有 NAT 或 proxy 伺服器。Your network is connected to the Internet without a NAT or proxy server.

除非您已停用 DHCP 相關的訊息,否則當您在 DHCP 位址和自動私人 IP 位址之間進行變更時,DHCP 訊息會提供通知給您。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 Edition 中的 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. 若要這麼做,您可以將 "IPAutoconfigurationEnabled" DWORD 登錄專案(其值為0x0)新增至 Windows Millennium Edition、Windows98 或 Windows 98 第二版的下列登錄機碼: 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,則可以停用 APIPA,方法是將具有值0x0 的 "IPAutoconfigurationEnabled" DWORD 登錄專案新增至下列登錄機碼: 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

當您為 DHCP) 設定的 Windows 電腦 (正在初始化時,它會廣播三個或多個「探索」訊息。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.