Windows 2000/XP command line DNS settings?

Xuttah

Member
May 10, 2000
127
0
0
I've looked at Microsoft's site and searched Google. Does anyone know if DNS settings can be set via the command line in W2K and/or WinXP Pro? The ipconfig documentation doesn't list any DNS options.

Thanks!
 

bsobel

Moderator Emeritus<br>Elite Member
Dec 9, 2001
13,346
0
0
I don't know of any built in tool to adjust dns settings from the command line. You could throw something together if you *really* needed this capability. Curious, what are you trying to do?
Bill
 

Xuttah

Member
May 10, 2000
127
0
0
I'd like to set my laptop up to access work-specific resources while at work, and home resources while at home, and I'd like to create a simple batch file with the commands to acheive it. I can set my routes and gateway just fine, but DNS is the missing piece. I'd like to avoid having to manually adjust each setting every day.

BTW, I'm simplifying this quite a bit to avoid a lengthy explanation. Home is straight DHCP, but work is what is complicated.

Thanks

 

Garet Jax

Diamond Member
Feb 21, 2000
6,369
0
71


<< I've looked at Microsoft's site and searched Google. Does anyone know if DNS settings can be set via the command line in W2K and/or WinXP Pro? The ipconfig documentation doesn't list any DNS options.

Thanks!
>>



Xuttah,

This probably won't help you much, but you can flush and reregister dns settings at the command prompt. This is useful if say you have NATing and the name of the internal machine is the same as the external machine.

In other words,

Inside the network you type

"nslookup nameA.domainA.com"&nbsp&nbspand you get&nbsp&nbsp"XXX.XXX.XXX.XXX"

Outside the network you type

"nslookup nameA.domainA.com"&nbsp&nbspand you get&nbsp&nbsp"YYY.YYY.YYY.YYY"

That way moving from inside the network to outside the network and back again screws up your settings because you keep searching for the same machine and keep getting different IP addresses.

To solve this, I typed the following two commands at my prompt and it solved the problem,

ipconfig /flushdns
ipconfig /registerdns

I know this works for Windows 2000 and not for Windows 98 or Windows 95. Unfortunately, I have no idea about Windows XP.
 

bsobel

Moderator Emeritus<br>Elite Member
Dec 9, 2001
13,346
0
0
Is work non dhcp? If so, you might be able to use the 'alternate tcp/ip' configuration that XP supports. The way it works is that you configure XP to use DHCP (for home), if a DHCP server can't be found it will use the alternate settings (you can specify ip/mask/gw/dns there).

Of course if works has dhcp too, this won't work (but brings up the question why you can't take the work dhcp defaults).

Best,
Bill
 

Xuttah

Member
May 10, 2000
127
0
0

Garet Jax,

That's a great thing to remember, and I appreciate your response. But I want to be able to set my resolvers in cmd line, not necessarily refresh domain lookups. At work, the resolvers for one network do not resolve addresses on the other network, so I must change my resolvers when I need to access resources on one network or the other.

But your tip sounds like something that will help in the future.
 

Xuttah

Member
May 10, 2000
127
0
0
bsobel,

I have two possible gateways I can use at work. There are mutually exclusive resources behind each gateway. I do receive a DHCP address, but in order to access resources behind each gateway simultaneously, I have my laptop set with static routes, and have a DNS resolver from each network as my primary/secondary so I can access both networks simultaneously. However, if I want to connect to my LAN at home, I set everything back to DHCP.

I just want to be able to write a batch file I can execute to set my routes, gateway, and DNS resolvers, rather than do it manually each time.

Thanks
 

afzan

Member
Nov 13, 2001
147
0
0
I don't know the answer to your question.

but could this possibly be done by using two different users? or two different connections that use the same nic?
 

Woodie

Platinum Member
Mar 27, 2001
2,747
0
0
DNS settings are kind-of TCP/IP settings, but they're not NIC centric.
Anyway, why don't you do a registry export of the DNS settings when you've got it set up in each of your environments. Then, in your batch file, just call the appropriate .reg file.
 

Xuttah

Member
May 10, 2000
127
0
0
Yes!! Woodie you da man. That's a great idea. Rather than mess with finding command line parameters, it would be just as easy to actually set values in the registry.

Thanks!!
 

bsobel

Moderator Emeritus<br>Elite Member
Dec 9, 2001
13,346
0
0
Except you'll find (I believe) the registry values won't take affect until you reboot, which I presumed your trying to avoid...
Bill
 

fastcobra

Senior member
Oct 12, 1999
683
0
0
use the netsh command
I have a .bat file I made to use at work, it sets the ip according to machine name and dns settings, pretty cool.
Email me and I will send it to you so I don't forget, cause AT forums are banned at work :(

Here it is, found it:
*********
echo
netsh interface ip set address "Local Area Connection" static 192.168.0.8 255.255.255.0 192.168.0.1 1
add dns "Local Area Connection" 200.100.100.1
add dns "Local Area Connection" 200.100.100.2
netsh exit
*********

Adjust accordingly
 

Xuttah

Member
May 10, 2000
127
0
0
One of the great improvements under W2K was that network changes take effect immediately, without the need to reboot (like NT 4, Win9x, etc...). I tested the batch file today. It runs on bootup and works great. I also set up easy Start-menu icons to move back and forth as needed.

I'd never heard of the netsh command or it's parameters. I'll be playing around with that as well. Thanks for the help!
 

gsaldivar

Diamond Member
Apr 30, 2001
8,691
1
81
I just found this thread, otherwise I would have posted sooner :)

I've been using NetSwitcher to toggle between the LAN at my college and my cable modem at home. Works instantly (without rebooting), and you can script it to do all kinds of other stuff when you change locations as well - like mounting servers, changing your e-mail profile, default printers, etc. etc...

It works great on W2K as well.

Good luck!