Change Default Gateway with a Batch file

Below is a useful script to change a default gateway IP address on a Windows 7 network adapter.

@ECHO OFF
Set Gateway=192.168.1.99
for /f "tokens=4*" %%a in ('netsh interface ipv4 show interfaces ^| find " connected" ^| find /v /i "Loopback"') do Set NIC=%%b
netsh interface ipv4 delete route prefix=0.0.0.0/0 interface="%nic%"
netsh interface ipv4 add route prefix=0.0.0.0/0 interface="%nic%" nexthop=%gateway% publish=Yes

Steve

Web Developer, IT enthusiast & PC Gamer.

Leave a Reply

Your email address will not be published. Required fields are marked *