Skip to content

Instantly share code, notes, and snippets.

@stoyanovgeorge
Last active January 27, 2025 17:09
Show Gist options
  • Save stoyanovgeorge/6c980a7f698c7816f704a49a9e5270e8 to your computer and use it in GitHub Desktop.
Save stoyanovgeorge/6c980a7f698c7816f704a49a9e5270e8 to your computer and use it in GitHub Desktop.
A batch script for Windows 10 which can change the IP address, the network mask, the gateway, the DNS and the VLAN ID of an interface. You need to execute the script with admin rights.
@echo off
:: Configuration Variables
set "ifName=Ethernet 2"
set "ipAddress=10.88.167.35"
set "subnetMask=255.255.255.240"
set "vlanID=702"
:: set "defaultGateway=x.x.x.x"
:: set "primaryDNS=x.x.x.x"
:: set "alternateDNS=x.x.x.x"
:: Change of IP address and NetMask ::
netsh interface ipv4 set address name="%ifName%" source=static addr=%ipAddress% mask=%subnetMask% gateway=%defaultGateway%
:: netsh interface ipv4 set dns "%ifName%" static %primaryDNS%
:: netsh interface ipv4 add dns "%ifName%" %alternateDNS% index=2
:: Disable ::
:: netsh interface set interface "%ifName%" DISABLED
:: Change VLAN ID ::
powershell -Command "& {Set-NetAdapter -Name '%ifName%' -VlanID %vlanID% -Confirm:$false}"
echo The VLAN ID of %ifName% has been successfully changed to %vlanID%
:: Enable ::
:: netsh interface set interface "%ifName%" ENABLED
powershell -Command "Start-Sleep -s 5"
:: pause > nul
@Gwedel
Copy link

Gwedel commented Jan 13, 2025

You should add gateway address to the script as well. Easiest to add to line 14 with gateway=%defaultGateway%

@stoyanovgeorge
Copy link
Author

@Gwedel thanks for the heads up, I have changed the GIST to contain your suggestion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment