Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Windows 綜合教學 >> 關於 Windows

Windows 批量新增 IP 位址兩大法:匯出/匯入設定檔與 FOR 迴圈指令

編輯:關於 Windows

伺服器需一次新增幾十上百個 IP 位址,透過控制台逐一新增極其低效。以下提供兩種命令列批量操作方案。

方法一:匯出設定檔 → 編輯 → 匯入 (適合固定 IP 陣列)

  1. 開啟 CMD (系統管理員),執行:
    netsh -c interface ip dump > c:\ip.txt
  2. 用文字編輯器開啟 c:\ip.txt,依現有格式新增所需 IP 區段 (建議先手動新增 2-3 組作為範本)。
  3. 執行匯入:
    netsh -f c:\ip.txt
  4. 完成無錯誤訊息即成功,至控制台確認。

方法二:FOR 迴圈指令批量新增連續 IP (適合連續網段)

範例:新增 192.168.1.163 至 192.168.1.190,子網路遮罩 255.255.255.224,介面卡名稱「乙太網路 2」:

FOR /L %i IN (163,1,190) DO netsh interface ip add address "乙太網路 2" addr=192.168.1.%i 255.255.255.224

參數說明:

  • (163,1,190):起始 IP 尾碼、遞增值、結束尾碼。
  • "乙太網路 2":請替換為實際網卡名稱 (netsh interface show interface 查詢)。
  • 192.168.1:網段前綴。
  • 255.255.255.224:子網路遮罩 (請依實際環境調整)。

在批次檔 (.bat) 中執行時,%i 需改為 %%i。

Copyright © Windows教程網 All Rights Reserved