經常在不同網路環境(辦公室、客戶現場、旅館、家中)移動的筆電使用者,手動改 IP 極其繁瑣。將 netsh 指令封裝成 .bat 腳本,雙擊即可套用預設網路配置。
netsh interface ipv4 set address name="乙太網路" source=static addr=192.168.20.11 mask=255.255.255.0 gateway=192.168.20.1 gwmetric=30
netsh interface ipv4 set address name="乙太網路" source=static addr=192.168.20.11 mask=255.255.255.0 gateway=192.168.20.1 gwmetric=30
netsh interface ipv4 add address name="乙太網路" addr=192.168.1.11 mask=255.255.255.0 gwmetric=30
關鍵差異:第一組用 set,後續追加用 add。
netsh interface ipv4 set address name="乙太網路" source=dhcp
netsh interface ipv4 set dns name="乙太網路" source=static addr=202.106.0.20 register=PRIMARY
netsh interface ipv4 add dns name="乙太網路" addr=202.106.46.151
office.batnetsh interface ipv4 set address name="乙太網路" source=static addr=192.168.20.11 mask=255.255.255.0 gwmetric=30
netsh interface ipv4 add address name="乙太網路" addr=192.168.1.11 mask=255.255.255.0 gwmetric=30
REM netsh interface ipv4 set dns name="乙太網路" source=static addr=202.106.0.20 register=PRIMARY
hotel.batnetsh interface ipv4 set address name="乙太網路" source=dhcp
netsh interface ipv4 set dns name="乙太網路" source=static addr=202.106.0.20 register=PRIMARY
netsh interface ipv4 add dns name="乙太網路" addr=202.106.46.151
name=)需與系統實際一致,可用 netsh interface show interface 查詢(常見為「乙太網路」、「區域連線」、「Ethernet」)。一鍵切換網路環境,告別手動點點點的痛苦。