Skip to content

Instantly share code, notes, and snippets.

@stoyanovgeorge
Last active April 13, 2024 20:11
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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%
:: 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 > null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment