Quick one today.
Wanted to change a servers default gateway in a CMD file. Easiest way to do it is to use NETSH. Its a very powerful tool (All Windows versions after XP) that has many uses from configuring the Windows Firewall to resetting branchcache.
In this instance I wanted to do a simple default Gateway change , so here’s the barebones of it:
Run this so we store the existing config which we can apply on an uninstall:
NETSH INTERFACE DUMP > conf.txt
The actual command to do the amendment:
NETSH INTERFACE IP SET ADDRESS NAME=”Local Area Connection” GATEWAY=172.16.0.1 GWMETRIC=0
The next bit is probably not needed, but I’ve put in just in case, the disablement and re-enablement of the NIC, careful here all network connectivity will be lost whilst this is performed:
netsh interface set interface “Local Area Connection” DISABLED
netsh interface set interface “Local Area Connection” ENABLED
…and there you go.
Oh and if you want to back this out:
NETSH INTERFACE EXEC CONF.TXT