Skip to content

Instantly share code, notes, and snippets.

@munim
Last active May 31, 2016 08:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save munim/cf6fb951e3d9278bf4bb1cc2d622d03a to your computer and use it in GitHub Desktop.
Save munim/cf6fb951e3d9278bf4bb1cc2d622d03a to your computer and use it in GitHub Desktop.
Windows script to change network adapter IP to static/DHCP

Change IP address using batch script in Windows 7 and above

Create a batch file, put the below script in and run it as administrator.

Static IP

@echo "Setting static IP."
@netsh interface ip set address "Ethernet0" static 192.168.1.100 255.255.255.0 192.168.1.1
@echo "Setting DNS."
@netsh interface ip set dns "Ethernet0" static 8.8.8.8
@echo "Restarting network interface."
@netsh interface set interface name="Ethernet0" admin=disabled
@netsh interface set interface name="Ethernet0" admin=enabled

DHCP

netsh interface ip set address "Ethernet0" dhcp
netsh interface ip set dns "Ethernet0" dhcp
@echo "Restarting adapter."
@netsh interface set interface name="Ethernet0" admin=disabled
@netsh interface set interface name="Ethernet0" admin=enabled

NB: You need to change the Ethernet0 to your connection name and IP addresses as required.

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