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

兩支批次檔搞定筆電固定 IP 與 DHCP 切換

編輯:XP 系統應用技巧

筆電在公司、家裡、咖啡廳等不同網路環境間移動,頻繁手動切換 IP 設定極為繁瑣。善用 Windows 內建 netsh 指令,寫成兩支批次檔(.bat),雙擊即可一鍵切換「固定 IP」與「自動取得 IP(DHCP)」,大幅提升行動辦公效率。

腳本一:切換至固定 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 "區域連線" static 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

說明:

  • 將 區域連線 替換為實際網卡名稱(如「乙太網路」、「Wi-Fi」)。
  • IP、子網路遮罩、閘道、DNS 請依實際網路環境修改。
  • index=2/3 為備用 DNS 伺服器順序。

腳本二:切換回 DHCP 自動取得

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

使用技巧

  1. 將兩支 .bat 檔放在桌面或快速啟動列。
  2. 右鍵內容 → 「進階」 → 勾選「以系統管理員身分執行」,避免權限不足失敗。
  3. 若在兩組固定 IP 間切換,複製第一支腳本並修改 IP 參數即可。

批次檔執行畫面

掌握這兩支腳本,筆電跨網域移動不再煩惱,真正做到「藥到病除」。

Copyright © Windows教程網 All Rights Reserved