I have a office that uses static IP addresses at the location. The manager just got a laptop that he wants to use at the office and at his house the same static address does not work. So I made him two batch files so he can easily switch between a static IP address in the office and a dynamic IP address at home. I was thinking that this could be helpful for making sure everyone in a office is using DHCP and no one is statically assigned. It could also be really useful for changing say the DNS server address on a set of computers automatically through a login script or kaseya.
It is a super simple script. The name of the network adaptor must be changed to match the name of the network adaptor you wish to modify settings for.
DHCP Through a batch/login script:
netsh int ip set dns name = “Local Area Connection” source = dhcp
netsh int ip set wins name = “Local Area Connection” source = dhcp
Static IP address through a batch/login script (change the red to match the addresses you need to set. IP is the IP address, SM is the subnet mask, gw is the default gateway, dns1 is the primary dns address, dns2 is the secondary dns address):
set ip=192.168.1.203
set sm=255.255.255.0
set gw=192.168.1.1
set dns1=4.2.2.2
set dns2=4.2.2.1
netsh int ip set address name = “Local Area Connection” source = static addr = %ip% mask = %sm%
netsh int ip set address name = “Local Area Connection” gateway = %gw% gwmetric = 1
netsh int ip set dns name = “Local Area Connection” source = static addr = %dns1%
netsh int ip add dns name = “Local Area Connection” addr = %dns2%
END
DHCP Set through Kaseya
Script Description: Enables DHCP on the local area conection  Â
IF True
THEN
Execute Shell Command
Parameter 1 : netsh int ip set dns name = “Local Area Connection” source = dhcp
Parameter 2 : 1
OS Type : 0
Execute Shell Command
Parameter 1 : netsh int ip set address name = “Local Area Connection” source = dhcp
Parameter 2 : 1
OS Type : 0
Execute Shell Command
Parameter 1 : netsh int ip set wins name = “Local Area Connection” source = dhcp
Parameter 2 : 1
OS Type : 0
ELSE
You can also use this same pattern to set just one line. For example to use kaseya to quickly change the DNS server address on several computers you can use this. (note 4.2.2.2 is a open DNS server but change it to match what you need):
Script Description: Sets DNS on Local Area connection to 4.2.2.2Â
IF True
THEN
Execute Shell Command
Parameter 1 : netsh int ip set dns name = “Local Area Connection” source = static addr = 4.2.2.2
Parameter 2 : 1
OS Type : 0
ELSE
#1 by Tania on May 2, 2009 - 9:44 pm
Everything dynamic and very positively!