Change DNS on Clients

Hello everyone,

It has been a week that I’m looking in different websites and forums for any kind of solution for this problem :
In my office the “Server Team” is going to change the DNS for good while my team, needs to verify that all computers on the network (1.200 clients) have the proper DNS and if not change it.
The first part was easy (knowing the DNS) but I don’t know how to write the code to actually change the DNS since I’ve started using bigfix like 3 months ago without any help.

I’ve found this : Would it be possible to change DNS settings (IP addresses) of workstation in bigfix? but it lead me to nothing

Any help on this would be great.
Thank you.

Which OSes are in scope here?

Fair Question.

Windows 7 and Win 10 Version 1709/1803

Windows 8.1 was skipped or it is installed only on clients that are always on DHCP

You have to be careful here as there can be multiple NICS and Wireless adapters…
I did this recently a while my code is not very elegant and a bit rough around the edges, it worked for me.
I copied the actionscript from someone else and added a bit.

Relevance:

Windows of operating system
(exists distinguished name of local computer of active directory)
exists (connection of network) whose (name of it starts with “Ethernet” or name of it starts with “Local Area Connection” or name of it starts with " NIC" )and status of (connection of network) whose (name of it starts with “Ethernet” or name of it starts with “Local Area Connection” or name of it starts with “NIC” ) = (connection status connected)

Action
// Change DNS Server //
action parameter query “DNSSVR1” with description “Enter the 1st New DNS server Address.” and with default value "xxx.xxx.xxx.xxx"
action parameter query “DNSSVR2” with description “Enter the 2nd New DNS server Address.” and with default value “xxx.xxx.xxx.xxx

regset “[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters]” “NameServer”="{parameter “DNSSVR1” of action,parameter “DNSSVR2” of action}"
// This will force the DHCP address to use the new DNS servers
// regset “[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters]” “DhcpNameServer”="{parameter “DNSSVR1” of action,parameter “DNSSVR2” of action}"

delete __createfile
createfile until END_CREATE
@echo off
netsh interface ip delete dnsserver “{name of connection whose (status of it = (connection status connected)and(name of it starts with “Ethernet” or name of it starts with “Local Area Connection” or name of it starts with “NIC”) ) of network}” all
netsh interface ip add dnsserver “{name of connection whose (status of it = (connection status connected)and(name of it starts with “Ethernet” or name of it starts with “Local Area Connection” or name of it starts with “NIC”) ) of network}” {parameter “DNSSVR1” of action}
netsh interface ip add dnsserver “{name of connection whose (status of it = (connection status connected)and(name of it starts with “Ethernet” or name of it starts with “Local Area Connection” or name of it starts with “NIC”) ) of network}” {parameter “DNSSVR2” of action}

netsh interface ip delete dnsserver “{friendly names of adapters whose (cidr string of it = wake on lan subnet cidr string) of network}” all
netsh interface ip add dnsserver “{friendly names of adapters whose (cidr string of it = wake on lan subnet cidr string) of network}” {parameter “DNSSVR1” of action}
netsh interface ip add dnsserver “{friendly names of adapters whose (cidr string of it = wake on lan subnet cidr string) of network}” {parameter “DNSSVR2” of action}
ipconfig /flushdns
END_CREATE

delete dns1.bat

move __createfile dns1.bat

waithidden dns1.bat

action requires restart

2 Likes

Thank you for the kind answer, Today I’ll give it a try and keep you posted.

Thank you.

It works like a charm.