Page 1 of 1 1
Topic Options
#142976 - 2005-07-05 04:08 PM Used netsh to change WINS/DNS settings for computers remotely?
thisistheurl Offline
Fresh Scripter

Registered: 2005-04-27
Posts: 12
Hi!

I am assigned to change the WINS and DNS settings on a lot of computers that use static settings (i.e. not DHCP).

Is it possible to do this safely remotely? Using netsh from Microsoft for example?

What I want to do is: Change the WINS and DNS settings and keep the other settings intact.

We use NT/2000/XP clients in an AD domain.

Any remote way would be great! It does not have to be (but definitly can be) a script solution. I will do this machine by machine though, still, remotely would be great so that I can save some time.

Top
#142977 - 2005-07-05 05:46 PM Re: Used netsh to change WINS/DNS settings for computers remotely?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Yes it can be done, but why are you not using DHCP to alter the DNS settings once the client is set to use a DHCP server?
 
Al_Po recently posted a UDF to enable DHCP


EnableDHCP() - Configures a NIC to use DHCP settings
 

Top
#142978 - 2005-07-06 12:34 AM Re: Used netsh to change WINS/DNS settings for computers remotely?
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
Well here's a start to a "Anti-EnableDHCP" UDF... its been tested some... but please test before using on production boxes.

Your silver platter code sir...

Examples:
? setstaticipoptions("IPAddress","192.168.0.101,255.255.255.0")
? setstaticipoptions("DefaultGW","192.168.0.1")
? setstaticipoptions("WINSServers","192.168.0.10,192.168.0.11")
? setstaticipoptions("DNSServers","192.168.0.10,192.168.0.11")
? setstaticipoptions("DNSDomain","MyDomain2.Com")

Code:
 
function SetStaticIPOptions($Setting,$Value,optional $remotepc)
dim $objWMIService, $colitems, $objnetadapter,$,$IP[0],$SM[0],$WS1,$WS2
$SetStaticIPOptions=1
if $remotepc=""
$remotepc="."
endif
$objWMIService = GetObject("winmgmts:\\" + $remotepc + "\root\cimv2")
if @error
exit @error
endif
$colItems = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=-1")
For Each $objNetAdapter In $colItems
Select
case $setting="DNSServers"
$=$objNetAdapter.SetDNSServerSearchOrder(split($value,","))
if @error
exit @error
else
$SetStaticIPOptions=0
endif
case $setting="WINSServers"
$WS1=split($value,",")[0]
if ubound(split($value,","))>0
$WS2=split($value,",")[1]
else
$WS2=""
endif
$=$objNetAdapter.SetWINSServer($WS1,$WS2)
if @error
exit @error
else
$SetStaticIPOptions=0
endif
case $setting="DNSDomain"
$=$objNetAdapter.SetDNSDomain($value)
if @error
exit @error
else
$SetStaticIPOptions=0
endif
case $setting="DefaultGW"
$=$objNetAdapter.SetGateways(split($value,","))
if @error
exit @error
else
$SetStaticIPOptions=0
endif
case $setting="IPAddress"
if instr($value,",")>0
$IP[0]=split($Value,",")[0]
$SM[0]=split($value,",")[1]
$=$objNetAdapter.EnableStatic($IP, $SM)
if @error
exit @error
else
$SetStaticIPOptions=0
endif
endif
endselect
Next
endfunction


Top
#142979 - 2005-07-06 12:39 AM Re: Used netsh to change WINS/DNS settings for computers remotely?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Al, think you should double check the documents of some of these calls. Some only apply to XP and won't work on 2000 as I recall.
 

Top
#142980 - 2005-07-06 12:47 AM Re: Used netsh to change WINS/DNS settings for computers remotely?
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
I don't have 2k box to test on... but I didn't see anything that said "limited to XP".

Doc, do you want to be my test monkey?

Top
#142981 - 2005-07-06 01:27 AM Re: Used netsh to change WINS/DNS settings for computers remotely?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Just double-checked for you and all your calls should work fine for both 2000/XP.

SetDynamicDNSRegistration is the one I was thinking of that only works for XP/2003
 

Top
#142982 - 2005-07-07 11:13 AM Re: Used netsh to change WINS/DNS settings for computers remotely?
thisistheurl Offline
Fresh Scripter

Registered: 2005-04-27
Posts: 12
Thanks for your script Allen! Altough I am not eager to try out something which isn't yet well tested. Also, as we are in a NT/2000/XP client environment a solution which could handle all those environments would benefit me a great deal.

Instead I am going for a netsh based solution:

My current netsh script
Code:

pushd interface ip

delete dns name=lo addr=all
delete wins name=lo addr=all

add dns name=lo addr=10.11.12.25 index=1
add dns name=lo addr=10.11.12.50 index=2

add wins name=lo addr=10.11.12.50 index=1
add wins name=lo addr=10.11.12.25 index=2

popd



The problem with the above is that despite the index values used above the result still is (part of ipconfig /all output):
Quote:


DNS Servers . . . . . . . . . . . : 10.11.12.25
10.11.12.50
Primary WINS Server . . . . . . . : 10.11.12.25
Secondary WINS Server . . . . . . : 10.11.12.50





They are in the same order as you can see. And I actually want 10.11.12.25 as the primary DNS and 10.11.12.50 as the primary WINS. Which I thought I did by adding the index values.. Hm.. Any suggestions fellas?

Top
#142983 - 2005-07-07 12:03 PM Re: Used netsh to change WINS/DNS settings for computers remotely?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
I think you should just concentrate on converting the clients to DHCP and then allow the DHCP Server to set the WINS/DNS entries for you.
 

Top
#142984 - 2005-07-07 06:12 PM Re: Used netsh to change WINS/DNS settings for computers remotely?
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
Its been tested some... and I think you would find it to do what you need with little or no effort. Based on what I've read it should work for NT4 SP4 too... Requires Windows XP, Windows 2000 Professional, or Windows NT Workstation 4.0 SP4 and later. I'd almost bet the requirements for using netsh are the same as using this WMI method.
Top
#142985 - 2005-07-07 06:28 PM Re: Used netsh to change WINS/DNS settings for computers remotely?
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
...for example...

? setstaticipoptions("WINSServers","10.11.12.50,10.11.12.25")
? setstaticipoptions("DNSServers","10.11.12.25,10.11.12.50")

Top
#142986 - 2005-07-07 11:10 PM Re: Used netsh to change WINS/DNS settings for computers remotely?
masken Offline
MM club member
*****

Registered: 2000-11-27
Posts: 1222
Loc: Gothenburg, Sweden
@thisistheurl, please explain why DHCP isn't an option. Walking around problems instead of solving them permanently is only useful in the short term if you're a consultant getting paid by the hour

Edited by masken (2005-07-07 11:11 PM)
_________________________
The tart is out there

Top
#142987 - 2005-07-07 11:19 PM Re: Used netsh to change WINS/DNS settings for computers remotely?
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
I resemble that remark
Top
#142988 - 2005-07-08 09:13 AM Re: Used netsh to change WINS/DNS settings for computers remotely?
thisistheurl Offline
Fresh Scripter

Registered: 2005-04-27
Posts: 12
It's not an option because it has been said that these machines should use static configuration, so that they are not dependent on the DHCP server to be online. Personally I would love to switch to DHCP as I don't think that security would be affected (as a redundant DHCP solution could be setup, which we do not have currently).

Anyway, it's not my decision to take and therefore isn't an option. If I had the authority to change how things are done in a lot of areas I would. As for now I can only comply with what others have decided and give my comments.

Top
#142989 - 2005-07-08 11:22 AM Re: Used netsh to change WINS/DNS settings for computers remotely?
masken Offline
MM club member
*****

Registered: 2000-11-27
Posts: 1222
Loc: Gothenburg, Sweden
Well it's a really strange decision. Your company has decided to have networking, but you haven't decided to have networking with it's most fundamental functions and requirements to work in the long run.

DHCP is a very basic function for networking. It also included functions like lease expiration. If the DHCP server cannot be contacted, the client sticks to it's current lease for X days, usually set somewhere between 3-7 days.

So actually, the motivation that DHCP should cause an instable network is actually as wrong as it can be. Basic networking functionality that usually have less stability is DNS and gateways/firewalls. And see where you are now, you need to change DNS-servers If you'd had DHCP, this wouldn't have been a problem at all.

I strongly suggest you go to your boss and say he's wrong. Send him here if he thinks he knows better
_________________________
The tart is out there

Top
#142990 - 2005-07-08 12:07 PM Re: Used netsh to change WINS/DNS settings for computers remotely?
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
If you want "static" addresses for some hosts you achieve this be assigning an address to the MAC address of the network adapter.

This is called a reservation, and means that the printer, switch, PC, server or whatever it is will always get the same address, but you still get the benefits from DHCP.

Top
#142991 - 2005-07-08 01:37 PM Re: Used netsh to change WINS/DNS settings for computers remotely?
thisistheurl Offline
Fresh Scripter

Registered: 2005-04-27
Posts: 12
It looks like you didn't read my answer (and yes, I have talked to my boss). I do know the benefits of using DHCP.

Edited by thisistheurl (2005-07-08 01:39 PM)

Top
#142992 - 2005-07-08 03:23 PM Re: Used netsh to change WINS/DNS settings for computers remotely?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
One small caveat when deploying DHCP. Keep in mind that a PC might not retain its lease if it loses contact with the DHCP server AND its default gateway.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#142993 - 2005-07-08 03:36 PM Re: Used netsh to change WINS/DNS settings for computers remotely?
thisistheurl Offline
Fresh Scripter

Registered: 2005-04-27
Posts: 12
I will keep it in mind. Maybe you are lucky enough to be able to decide things like that yourself. But it's a different story here with a lot of non technical things involved, company politics. The best technical solution isn't always possible, sad but true. Thanks for your feedback though!
Top
#142994 - 2005-07-08 03:56 PM Re: Used netsh to change WINS/DNS settings for computers remotely?
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Yes, I did read your answer. You said:
Quote:

It's not an option because it has been said that these machines should use static configuration, so that they are not dependent on the DHCP server to be online.




Well, after the lease has been give out for the first time there is *no* dependancy on a DHCP server being online at all. If someone has told you that there is then they don't understand DHCP.

The only dependancy is that if a lease cannot be renewed it will eventually expire and the address will be given up.

The lease is renewed half-way through the leased period, and if the DHCP server is off-line at this time the client will continue to attempt to renew the lease periodically.

This means that if the lease period is set at the default (7 days) and your DHCP server fails you have ~3.5 days to get it working again before leases will start to expire. If you think you might have an outage of more than 3.5 days set your lease to something longer, say 30 days. That will give you two weeks to get your server up and running again.

The only other time that you will have an issue if the DHCP server is unavailable and where the client has explicitly released the lease, or where it has moved to a new subnet and the DHCP data it has (IP address / gateway) are not valid. Neither of these situations apply to "static" devices.

So maybe you still cannot use DHCP because you cannot get support for it and I can imagine how frustrating that is, but the next time someone implies that the DHCP server has to be up for DHCP clients to work you can put them straight.

For more reading:

Top
#142995 - 2005-07-11 11:48 AM Re: Used netsh to change WINS/DNS settings for computers remotely?
thisistheurl Offline
Fresh Scripter

Registered: 2005-04-27
Posts: 12
Thanks for the information! Much appreciated!
Top
Page 1 of 1 1


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1376 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.086 seconds in which 0.038 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org