在管理員命令提示字元下,單行 netsh 指令即可設定介面卡靜態 IP,適合批次檔自動化、遠端部署、快速切換網路環境。
netsh interface ip set address "介面卡名稱" static IP位址 子網路遮罩 預設閘道
將「區域連線」設為 192.168.1.100、遮罩 255.255.255.0、閘道 192.168.1.1:
netsh interface ip set address "區域連線" static 192.168.1.100 255.255.255.0 192.168.1.1
netsh interface ip set dns "區域連線" static 8.8.8.8 primary
netsh interface ip add dns "區域連線" 8.8.4.4 index=2
netsh interface ip show config
輸出中「介面名稱」即為指令所需名稱(如「乙太網路」、「Wi-Fi」、「區域連線」)。
netsh interface ip set address "介面卡名稱" dhcp
netsh interface ip set dns "介面卡名稱" dhcp
將上述指令存為 .bat 批次檔,以管理員身分執行即可一鍵切換靜態/DHCP 模式,極適合筆電在公司/家裡/客戶端間頻繁切換網路環境。