Barry Kay
asked on
Change DNS settings in a (CMD) Command file.
We have a user that works at two locations. He is running Windows 10.
At location 1 he has DHCP with the DNS IP addresses he needs.
At location 2 we need to manually set static DNS for him to access some crucial applications.
We don't just leave the static DNS IPs on because this affects his normal internet access when at home or elsewhere.
I would would like to setup two command files (.CMD) that will change the DNS settings for his NIC per location.
- Command file 1 - DHCP DNS
- Command file 2 - Static DNS
What command line can I use to do this?
T.I.A
At location 1 he has DHCP with the DNS IP addresses he needs.
At location 2 we need to manually set static DNS for him to access some crucial applications.
We don't just leave the static DNS IPs on because this affects his normal internet access when at home or elsewhere.
I would would like to setup two command files (.CMD) that will change the DNS settings for his NIC per location.
- Command file 1 - DHCP DNS
- Command file 2 - Static DNS
What command line can I use to do this?
T.I.A
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open Notepad and paste below. You have to make two files HOMEDNS.bat and OFFICEDNS.bat
But change the name of LAN card. Here in my case is Ethernet so you have to check in user's laptop. Above script has been tested on my Windows 10 pro machine. If you need script in powershell I can provide.
Don't forget to change the extension to .Bat
@ECHO OFF
set vardns1=8.8.8.8
set vardns2=208.67.222.222
ECHO Setting Primary DNS
netsh int ip set dns name = "Ethernet" source = static addr = %vardns1%
ECHO Setting Secondary DNS
netsh int ip add dns name = "Ethernet" addr = %vardns2%
ipconfig /flushdns
exit
But change the name of LAN card. Here in my case is Ethernet so you have to check in user's laptop. Above script has been tested on my Windows 10 pro machine. If you need script in powershell I can provide.
Don't forget to change the extension to .Bat
ASKER
Thank you for the suggestions.
Ideally DNS should be able to handle all traffic with either creating multiple dns zones or appending dns suffix search list etc
Else,
alternate IP configuration is the better option than using software for that which completely eliminate user intervention
U can set static IP on all workstation once in other location with customized DNS settings and forget it.
When user at home, he will get IP from ISP DHCP and connect to internet.
When user comes to company, since DHCP is not available he would automatically use alternate configuration