圖形介面設定 IP 有時失效 (Win10 預覽版、Server Core、遠端無桌面),`netsh interface ip` 指令提供完整命令列解決方案。本文整理單行指令模式、參數對照、恢復 DHCP、DNS 設定、PowerShell 現代替代方案,適用 Win7/8/10/11/Server 全系列。
Win+R → `cmd` → Ctrl+Shift+Enter (或右鍵「以系統管理員身分執行」)。


:: 設定靜態 IP (介面名稱需完全一致,含空格請加雙引號)
netsh interface ip set address "乙太網路" static 192.168.1.100 255.255.255.0 192.168.1.1 1
:: 設定靜態 DNS
netsh interface ip set dns "乙太網路" static 8.8.8.8
:: 新增第二組 DNS
netsh interface ip add dns "乙太網路" 8.8.4.4 index=2
:: 恢復 DHCP 自動取得 IP
netsh interface ip set address "乙太網路" dhcp
:: 恢復 DHCP 自動取得 DNS
netsh interface ip set dns "乙太網路" dhcp
:: 查詢目前設定
netsh interface ip show config "乙太網路"
netsh interface ip show dnsservers "乙太網路"
| 參數 | 範例 | 說明 |
|---|---|---|
| 介面名稱 | "乙太網路", "Wi-Fi", "區域連線" | 需與 `ncpa.cpl` / `netsh interface show interface` 顯示完全一致,支援中文,必須英文雙引號 |
| static | static | 指定靜態參數模式 |
| IP 位址 | 192.168.1.100 | 目標靜態 IP |
| 子網路遮罩 | 255.255.255.0 | /24 等同 255.255.255.0 |
| 預設閘道 | 192.168.1.1 | 路由器 LAN IP |
| 閘道度量 | 1 | 結尾必須輸入 1 代表啟用,不可省略 |
# 設定靜態 IP
New-NetIPAddress -InterfaceAlias "乙太網路" -IPAddress 192.168.1.100 -PrefixLength 24 -DefaultGateway 192.168.1.1
# 設定 DNS
Set-DnsClientServerAddress -InterfaceAlias "乙太網路" -ServerAddresses 8.8.8.8, 8.8.4.4
# 恢復 DHCP
Remove-NetIPAddress -InterfaceAlias "乙太網路" -IPAddress 192.168.1.100 -Confirm:$false
Set-DnsClientServerAddress -InterfaceAlias "乙太網路" -ResetServerAddresses
# 查詢
Get-NetIPConfiguration -InterfaceAlias "乙太網路"
將指令封裝為 `.bat`/.ps1,搭配 `psexec`/`Invoke-Command` 實現多機器批次靜態 IP 佈署,或整合至 MDT/SCCM/Ansible 任務序列。