Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 822
  • Last Modified:

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.
0
Menshen
Asked:
Menshen
  • 2
1 Solution
 
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

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now