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 run a dns server on a linux machine for testing local versions of my websites. I have configured my client machine in network connections to use this dns server.

However if my linux machine dies or I reboot it, I have to manually go into network connections and change my dns settings back to my isps dns server.

Is there any way that I can configure my client machine to use my dns server if it can be contacted, if not it uses a different address?

I am aware that there is the alternative dns server setting but If I put anything in there it sometimes uses primary, sometimes alternative. I want alternative to be only used if primary is unavailable.

EDIT: I don't think I made my question very clear. I don't have any problem with my dns server, that is set up fine. But if for some reason it is unreachable and can not be contacted clients (windows and linux) can not browse the internet because they are looking for a non existent dns server. In this case I want them to use a different dns server.

share|improve this question
add comment

2 Answers

If the DNS server stops working when you reboot you simply need to sort out why that is (See man chkconfig on some Linux versions).

You haven't said what O/S your client machine is running. In either event, I'd suggest using DHCP to dole out your DNS settings.

share|improve this answer
add comment

The place to configure your DNS servers is /etc/resolv.conf. It will contain something like:

search example.com
nameserver 192.168.0.1
nameserver 192.168.0.2

Nameservers are specified using the nameserver option and are used in the order they're specified, so this client will use 192.168.0.1 unless it doesn't respond for 5 seconds, in which case it will try 192.168.0.2. The search option is a list of domains suffixes to add to requests if a lookup fails (By default if your query has no dot in, and therefore probably just a hostname, the resolver will not do an initial query and just try adding the suffixes).

This file is normally static. You would normally edit it by hand or use some GUI tool to do it for you. This is what you are doing when you use the networks connection settings.

However, if you have an interface configured for DHCP, the DHCP server can give out nameservers, so the DHCP client has to update the file. DHCP requests will normally happen at boot time and also when the lease runs out (which is controlled by the server; could be hourly, daily or anywhere in between).

It is also possible that some other configuration system is rewriting your resolv.conf on boot up. Linuxconf was prone to do this. You might find a comment in /etc/resolv.conf warning you not to edit the file because it will get overwritten if this is the case. This might give you a clue what to change.

As you have to keep reconfiguring your servers after boot and you don't specify what version of linux you are using, I'll make an assumption that it is DHCP causing the problem. There are a couple of solutions. First, you could change the DHCP server to give out the right DNS servers. This may not be desirable or possible if you don't control the server or you don't want everyone on the network to get those DNS servers. The second solution is to tell the client to ignore the options from the server. You may find a GUI option to do this, but more likely, You're going to have to do this by hand. You can do this by editing dhclient.conf (/etc/dhcp3/dhclient.conf on Debian and Ubuntu) and adding the following line:

supersede domain-name-servers 192.168.0.1 192.168.0.2;
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.