Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Windows 綜合教學 >> 關於 Windows

Windows 批次檔快速設定靜態 IP、子網路遮罩、閘道、DNS 指令碼

編輯:關於 Windows

將下列程式碼存為 setip.bat,以系統管理員身分執行即可快速套用固定 IP 設定:

@echo off
echo 正在設定 IP,請稍候...

set name="區域連線"
set ipaddress=192.168.1.100
set mask=255.255.255.0
set gateway=192.168.1.1
set dns=192.168.1.1
set wins=8.8.8.8

echo 正在設定 %name% ...
echo 設定慣用 DNS: %dns% ...
netsh interface ip set dns name="區域連線" source=static addr=%dns%
echo 設定備用 DNS: %wins% ...
netsh interface ip add dns "區域連線" addr=%wins% index=2

echo 設定 IP、子網路遮罩、閘道: %ipaddress% %mask% %gateway% ...
netsh interface ip set address name=%name% source=static addr=%ipaddress% mask=%mask% gateway=%gateway%
echo IP 設定完成!

pause

使用說明:

  • 將 name、ipaddress、mask、gateway、dns、wins 依實際環境修改。
  • 介面名稱(name)若非「區域連線」,請用 netsh interface show interface 查詢正確名稱。
  • 重要技巧: DNS 設定指令務必置於 IP 設定指令 之前,否則可能出現「設定的 DNS 伺服器不存在或不正確」錯誤。

此批次檔適用於 Windows 7/8/10/Server,方便筆電在不同網路環境(公司、家裡、實驗室)快速切換固定 IP。

Copyright © Windows教程網 All Rights Reserved