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

筆記本 IP 切換自動化:兩支 netsh 批次檔輕鬆搞定辦公與家庭環境

編輯:XP 系統應用技巧

頻繁攜帶筆記本在辦公室、家庭、會議室間移動,手動切換 IP 極為繁瑣。本文提供兩支 netsh 批次指令碼,一鍵切換 DHCP 與固定 IP(含 DNS),無需額外軟體。

腳本 1:切換為 DHCP 自動取得 IP

@echo off
netsh interface ip set address name="區域連線" source=dhcp
netsh interface ip set dns name="區域連線" source=dhcp

腳本 2:切換為固定 IP(範例)

@echo off
netsh interface ip set address "區域連線" static 192.168.0.84 255.255.255.0 192.168.0.254
netsh interface ip set dns "區域連線" 192.168.0.254
netsh interface ip add dns "區域連線" 202.106.196.115 index=2
netsh interface ip add dns "區域連線" 202.106.0.20 index=3

使用說明

  • "區域連線" 為網卡名稱,可能為 "區域連線 2" 或英文 "Local Area Connection",請依實際修改
  • 固定 IP、子網路遮罩、閘道、DNS 請替換為實際環境值
  • 若在兩組固定 IP 間切換,複製腳本 2 修改 IP 即可
  • 儲存為 .bat 或 .cmd,右鍵「以管理員身分執行」生效

兩支腳本放入桌面或快捷列,隨時一鍵切換網路環境,告別手動設定煩惱。

Copyright © Windows教程網 All Rights Reserved