要使用CMD命令修改网络适配器的IP地址,请按以下步骤操作(需管理员权限):
步骤 1:以管理员身份打开CMD
- 搜索
cmd
→ 右键选择 "以管理员身份运行"。
步骤 2:查看当前网络适配器名称
netsh interface ip show config
- 找到要修改的适配器名称(如
"以太网"
、"WLAN"
或"本地连接"
)。
步骤 3:设置静态IP地址
netsh interface ip set address name="适配器名称" static <新IP> <子网掩码> <默认网关>
示例 (将 以太网
的IP设为 192.168.1.100
):
netsh interface ip set address name="以太网" static 192.168.1.100 255.255.255.0 192.168.1.1
步骤 4:设置DNS服务器
netsh interface ip set dns name="适配器名称" static <首选DNS>
netsh interface ip add dns name="适配器名称" <备用DNS> index=2
示例 (设置DNS为 8.8.8.8
和 8.8.4.4
):
netsh interface ip set dns name="以太网" static 8.8.8.8
netsh interface ip add dns name="以太网" 8.8.4.4 index=2
步骤 5:恢复自动获取IP(DHCP)
netsh interface ip set address name="适配器名称" source=dhcp
netsh interface ip set dns name="适配器名称" source=dhcp
常见问题
-
适配器名称错误:
-
检查名称是否与步骤2的结果完全一致(包括引号)。
-
示例:
name="以太网"
(中文系统)或name="Ethernet"
(英文系统)。
-
-
权限不足:
- 务必使用管理员身份运行CMD。
-
IP冲突:
- 确保新IP未被局域网其他设备占用。
命令说明
命令 | 作用 |
---|---|
netsh interface ip show config |
查看所有适配器配置 |
netsh interface ip set address |
设置IP/网关 |
netsh interface ip set dns |
设置DNS |
source=dhcp |
启用自动获取 |
⚠️ 修改后可能影响网络连接,请确保输入正确的网关和DNS(可咨询网络管理员)。