Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I m not sure if this is possible, but is there a way to update the dns server ip on all clients without doing it manually for each machine?

All clients have static IP addresses and the dns server is on a fedora box using bind. Clients are all unix boxes.

UPDATE: How would you do it for a windows box?

share|improve this question
add comment

3 Answers

up vote 5 down vote accepted

I'd write a script to modify /etc/resolv.conf using my favorite scripting language of choice and execute it on each remote machine w/ SSH.

Assume the old DNS server is 192.168.1.1 and the new is 192.168.100.100:

perl -pi -e's/192.168.1.1/192.168.100.100/' /etc/resolv.conf

Just execute that on the remote machines using SSH and you're golden. (Hopefully you have certificate-based authentication set up so that you're not keying passwords to connect to each host.)


Edit: On a Windows box

The "netsh" command is your friend. Assuming the network connection still has the name "Local Area Connection", you can do:

netsh interface ip set dns name="Local Area Connection" static 192.168.100.100 primary

That will set the primary DNS server specified on the connection "Local Area Connection".

If the connection has been renamed then you're probably best off dumping the configuration with netsh interface ip dump, parsing that output, and using netsh to make the necessary changes.

share|improve this answer
    
Thanks, I thought of that. Was wondering if there was something else out there. –  ankimal Dec 3 '09 at 18:50
    
To nitpik: echo '192.168.1.12' | perl -p -e's/192.168.1.1/192.168.100.100/' , will end up returning 192.168.100.1002. To simply the problem, I would probably use Regex::Common::Net. If you really don't want a module, than maybe perl -ple 's/nameserver\s+192\.168\.1\.1\D/nameserver 192.168.100.100/' would be better, but regexes can be tricky for these sorts of things, and I still might be missing an edge case. –  Kyle Brandt Dec 4 '09 at 13:47
    
@Kyle: It's a good nit to pick. I wasn't thinking about any kind of partial matches or edge cases. Obviously, one should test the heck out of a simple script like this before hitting any number of machines (and, yeah, it would be a lot easier if the OP just DHCP). –  Evan Anderson Dec 4 '09 at 14:18
    
Evan: Thanks for the kind words :-) I was more trying to get across the "don't parse IP address with regex" that people have pounded into my head. For me this is in parallel with 'Don't parse HTML with regex' I hear a lot, but obviously on a smaller scale :-) Jeff Atwood recently talked about parsing HTML with regex in his blog: codinghorror.com/blog/archives/001311.html –  Kyle Brandt Dec 4 '09 at 14:24
    
Oh, and also wanted to get across for future readers that the periods are not literal, but match any character (not that I think you don't already know this stuff). By the way, got a nice email from someone last night thanking me for the sub netting question (he might have thought I wrote your answer). He said it really helped him! –  Kyle Brandt Dec 4 '09 at 14:38
show 1 more comment

Well, if these clients are not servers, maybe now is the time to consider deploying DHCP if you haven't considered this already? Then you would just change it in the DHCP server, and reboot the clients or have the clients run sudo dhclient.

share|improve this answer
    
Definite +1 for this one. –  Jimmy Shelter Dec 3 '09 at 21:27
    
Thats easy but all these clients have static addresses and are ont DHCPed. –  ankimal Dec 3 '09 at 21:28
    
ankimal: My bad, I meant to say "If you haven't already", As in if you haven't considered it already, going to correct... –  Kyle Brandt Dec 3 '09 at 23:06
    
+1 - DHCP is The Right Thing(tm) here, ultimately. –  Evan Anderson Dec 4 '09 at 14:18
add comment

On Windows, if you have a domain, you can push out a new DNS server through group policy. What's strange is it won't display the new value in ipconfig, but it will still use it for actual name resolution (you can test that with nslookup).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.