如何在沒有 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). 有了這項功能,Windows 電腦就可以在 DHCP 伺服器無法使用或不存在於網路上時,指派網際網路通訊協定 (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 電腦可以自動將網際網路通訊協定指派 (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 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. 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 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.

  • 您的網路已連線到網際網路,但沒有 NAT 或 proxy 伺服器。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 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. y 是用戶端的唯一識別碼) ,則電腦會使用 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 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,可以藉由將 "IPAutoconfigurationEnabled" DWORD 登錄專案(值為0x0)新增至下列登錄機碼來停用 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

當您為 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.