Batch file to configure TCP-IP remotely?

Hi,

I need a batch file that will allow me to change the DNS configuration of hundreds of remote machines, I imagine maybe netsh will do the work since these are XP workstations, but I don't know exactly how.

The ideia is to change all just by running a batch file when required (preferably not a log on script), let's say for all the computers in subnet 192.168.1.0, the new DNS server is 192.168.1.2.

On a second step, on a different batch file, I would need to change all to DHCP clients... This would be done only after a couple of days, so I want separate batch files.
MenshenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jeff BeckhamEngineerCommented:
You can change just the local DNS for a machine via:

   netsh interface ip set dns name="Local Area Connection" static addr=<a.b.c.d>
   netsh interface ip add dns name="Local Area Connection" addr=<w.x.y.z> index=2

You can change local IP, DNS and WINS settings to DHCP via:

   netsh interface ip set address name="Local Area Connection" source=dhcp
   netsh interface ip set dns name="Local Area Connection" source=dhcp
   netsh interface ip set wins name="Local Area Connection" source=dhcp

In order to execute the command on a remote machine, you can either use the -r functionality of netsh or a 3rd-party utility like psexec (see: http://www.sysinternals.com/Utilities/PsExec.html).
0
MenshenAuthor Commented:
psexec looks fantastic, could you help me with the correct sintax to create the batch file?

If my desired static DNS was 192.168.02, I imagine something like this:

C:\psexec.exe \\192.168.0.103 netsh interface ip set dns name="Local Area Connection" static addr=192.168.0.2
C:\psexec.exe \\192.168.0.104 netsh interface ip set dns name="Local Area Connection" static addr=192.168.0.2
C:\psexec.exe \\192.168.0.105 netsh interface ip set dns name="Local Area Connection" static addr=192.168.0.2

... could work, but the second line would be processed on the remote computer also... Where psexec.exe is not present. what command can I use so that the next line is run on the local machine, and so on?
0
Jeff BeckhamEngineerCommented:
You don't need psexec.exe on the remote machine.  The only thing that's required on the remote machine would be netsh.

I'd recommend though that if you have more than one netsh command to execute on each remote mahine, that you create a batch file with the netsh commands in it.  For example, create a file named "go-dhcp.cmd" and place the following commands in it:

   netsh interface ip set address name="Local Area Connection" source=dhcp
   netsh interface ip set dns name="Local Area Connection" source=dhcp
   netsh interface ip set wins name="Local Area Connection" source=dhcp

Then, use the -c option from psexec to copy the batch file to the remote machine before executing it.  Example:

   psexec \\<remote_ip> -c go-dhcp.cmd

To run psexec against more than one computer, you can run it like you've indicated above or you can place more than one IP on the command line like:

   psexec \\<remote_ip1>,<remote_ip2>,<remote_ip3>,<remote_ip4> -c go-dhcp.cmd

Yet another option is place them in a file and tell psexec to process the file.  As an example and assuming text file named "pclist.txt" with a list of computer names or IPs in it:

   psexec @pclist.txt -c go-dhcp.cmd
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows XP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.