透過 netsh 指令可在腳本或遠端快速設定靜態 IP、子網路遮罩、預設閘道與 DNS,適合自動化部署或無圖形介面環境。
Win+R → cmd → Enter
netsh interface ip set address "連線名稱" static 新IP 子網路遮罩 閘道 1
範例:
set address "乙太網路" static 192.168.1.6 255.255.255.0 192.168.1.1 1
netsh interface ip set address "乙太網路" static 192.168.1.108 255.255.255.0 192.168.1.1 1
netsh interface ip set address "乙太網路" dhcp
netsh interface ip set dns "乙太網路" static 8.8.8.8
新增第二組 DNS:
netsh interface ip add dns "乙太網路" 8.8.4.4 index=2
netsh interface ip set dns "乙太網路" dhcp
netsh interface ip show config
1 代表確認覆寫。