注釋 : 用來將 IP 地址配置模式從 DHCP 模式改為 static,或從 static 模式改為 DHCP。用靜態 IP 地址在接口上添加 IP 地址,或添加 默認網關。 示例 :
set address name="Local Area Connection" source=dhcp set address local static 10.0.0.9 255.0.0.0 10.0.0.1 1 ----------------------------------------------------------------------------
至此,命令行下設置IP完成。 同時你還可以在命令行下更改DNS設置,用的是set dns命令,你可以輸入set dns /?查看使用方法。
最后,我們將這些命令保存為一個BAT文件(setIP192168423.bat):
復制代碼 代碼如下:
@echo off rem eth //eth 為網卡名稱,可在網絡連接中查詢,如"本地鏈接" set eth="本地鏈接" rem ip //ip 為你想更改的IP set ip=192.168.4.23 rem gw //gw 為網關地址 set gw=192.168.4.1 rem netmasks //netmasks 為子網掩碼 set netmasks=255.255.255.192
echo 正在將本機IP更改到: %ip% rem if %gw%==none netsh interface ip set address %eth% static %ip% %netmasks% %gw% > nul if not %gw%==none netsh interface ip set address %eth% static %ip% %netmasks% %gw% 1 > nul echo......................... echo 檢查當前本機IP: ipconfig echo......................... echo 成功將本機IP更改為%ip%! pause close