Home > SCRIPTING > netsh – Scripts to change IP settings

netsh – Scripts to change IP settings

  • Sharebar

Netsh.exe is a tool an administrator can use to configure and monitor Windows-based computers at a command prompt. With the Netsh.exe tool, you can direct the context commands you enter to the appropriate helper, and the helper then carries out the command. A helper is a Dynamic Link Library (.dll) file that extends the functionality of the Netsh.exe tool by providing configuration, monitoring, and support for one or more services, utilities, or protocols. The helper may also be used to extend other helpers.

setting the IP address, Subnetmask and Gateway

This single line of code sets the IP address, Subnetmask and Gateway of a specific network adapter on any windows machine. It can eigther be executed inside a command line or from a batch script.
In this specific case the name of the network adapter is ‘LAN-Connection’, the IP address to be set is, the subnetmask is and the default gateway should be set to The name of the network interface can be looked up using the ipconfig command.

netsh interface ip set address “Local Area Connection” static 1

setting the DNS server

To set the DNS servers which should be used the following command is used:
The first line sets the primary nameserver and the second line sets the secondary nameserver. If ther is only one nameserver available the second line can be skipped.

netsh interface ip set dns name=”Local Area Connection” source=static addr= register=primary
netsh interface ip add dns name=”Local Area Connection” addr= index=2

using DHCP

DHCP (Dynamic Host Configuration Protocol) Service which sets all IP settings automatically. However to make use of this service the network adapter has to be configured to listen to this protocol. Of course this can also be done with the help of netsh.
The first line is used to configure the IP address, subnetmask and gateway automatically with the help of DHCP. However the DNS servers are still not updated. Therfore the second line updates also the DNS settings.

netsh int ip set address name = “Local Area Connection” source = dhcp
netsh int ip set dns name = “Local Area Connection” source = dhcp

  1. No comments yet.
  1. No trackbacks yet.

Uses wordpress plugins developed by www.wpdevelop.com Copy Protected by Chetans WP-Copyprotect.