Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

Windows 靜態/動態 IP 一鍵切換批次檔 (netsh 版)

編輯:系統常見問題解答

提供兩個即用批次檔,分別將指定網卡切換為靜態 IP 或 DHCP 動態取得,適合頻繁在不同網路環境移動的筆電使用者。

靜態 IP 批次檔 set_static_ip.bat

@echo off
rem === 修改以下變數 ===
set "NIC=區域連線"
set "IP=172.24.83.239"
set "MASK=255.255.255.0"
set "GW=172.24.83.247"
set "DNS1=172.24.102.110"
set "DNS2=172.24.102.110"
rem ====================

netsh interface ip set address "%NIC%" static %IP% %MASK% %GW%
netsh interface ip set dns "%NIC%" static %DNS1% primary
netsh interface ip add dns "%NIC%" %DNS2% index=2
echo 靜態 IP 設定完成
pause

動態 DHCP 批次檔 set_dhcp_ip.bat

@echo off
set "NIC=區域連線"
netsh interface ip set address name="%NIC%" source=dhcp
netsh interface ip set dns name="%NIC%" source=dhcp
echo 已切換為 DHCP 自動取得 IP
pause

使用提醒

  • 以系統管理員身分執行 (右鍵選單)。
  • NIC 變數必須完全符合「網路連線」介面名稱 (含空格)。
  • 可建立捷徑放桌面,屬性 → 進階 → 勾選「以系統管理員身分執行」,雙擊即用。
  • 若有多張網卡,複製腳本修改 NIC 變數即可 (如「Wi-Fi」、「乙太網路 2」)。
Copyright © Windows教程網 All Rights Reserved