2

I'm running some tests on a Debian server. The network in which this server is located has two DNS servers (I don't know why and I can't change this). I used to need to point /etc/resolv.conf to one of these servers and I recently had to change which server I use. Since I changed /etc/resolv.conf to point to the new server, the configuration keeps changing behind my back every few days (it changes back to the old server).

For all I know, the machine has not rebooted. What should I check to figure out why this happens, and how can I stop it?

André Caron
  • 161
  • 1
  • 1
  • 7

3 Answers3

4

You are probably using DHCP for automatic IP configuration.

Best option to try:

/etc/dhclient.conf 

or

/etc/dhcp/dhclient.conf 

file contains configuration information for dhclient. You can toggle the DNS updates/ point to different DNS server from this file. The man pages for DHCLIENT.CONF and DHCP-OPTIONS point out that in dhclient.conf, you should add this:

option domain-name-servers 8.8.8.8 8.8.4.4

where

8.8.8.8 8.8.4.4

are DNS server IPs

Following link have more scenarios/possible solutions covered.

kaji
  • 2,528
  • 16
  • 17
  • 1
    I've just tried option #3 in the article you linked to. I think this is the best way to proceed since it is the method that least affects the the current server configuration. I'll give it a couple of days to see if it works as expected. Thanks. – André Caron Apr 17 '12 at 20:30
  • We really do prefer answers to have content, not just pointers to content. Whilst this may theoretically answer the question, [it would be preferable](http://meta.stackexchange.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – user9517 Apr 17 '12 at 20:51
  • @lain: This still the most useful answer to the question. I don't feel it merits a downvote because it's only a link. – André Caron Apr 17 '12 at 21:09
  • @lain : yes updated the answer – kaji Apr 18 '12 at 05:24
  • @AndréCaron: It may be useful 'today' but links have a habit of going dead so it's not useful for tomorrow. – user9517 Apr 18 '12 at 13:05
  • Isn't a semi-colon required at the end? `option domain-name-servers 8.8.8.8 8.8.4.4;` – kodybrown Jan 30 '17 at 22:49
  • And, other examples also show a comma between the name-servers `option domain-name-servers 8.8.8.8, 8.8.4.4;` I just want to be sure i'm at the correct file, etc.. – kodybrown Jan 30 '17 at 22:49
2

On a server (or anything that's not being moved around a lot, or at least has a static IP) you don't need tools that automagically configure networking for you. It just gets in the way.

Remove the following:

apt-get --purge remove resolvconf network-manager

Then kill any dhcp client that may still be running:

ps -ef|grep dhcp
kill PID   <-- i.e. the ID of any process you found

Once done I am pretty sure your networking and resolv.conf will not mysteriously change anymore.

After that make sure your resolv.conf as well as your network configuration are configured the way you want it to be. Any changes you make will stay that way.

aseq
  • 4,610
  • 1
  • 24
  • 48
  • 1
    I'm really quite ignorant of network configurations, so do you have any relevant documentation on what this does and why it works? I don't want to blindly paste commands into the shell and cross my fingers... – André Caron Apr 17 '12 at 20:03
  • Networkmanager uses some logic to determine what kind of networking you need, like wireless, or cable, and change the connection accordingly. Resolvconf is a framework for keeping up to date the system's information about name servers. Neither is needed on a system where such information remains static. – aseq Apr 17 '12 at 20:05
  • But I don't want to disable *everything* the DHCP service does. I only want to prevent it from "updating" the `resolv.conf` file. It seems the `apt-get --purge remove resolvconf network-manager` would do (only) this, but why should I kill the running DHCP service? – André Caron Apr 17 '12 at 20:26
  • If you're running a dhcp server and you need it leave it running. Just kill the dhcp-client that may be running. You can recognise it by the "client" part when you do "ps -ef|grep dhcp". If it's not there all the better. – aseq Apr 17 '12 at 20:37
  • I've just tried the instructions for option #3 in [kaji's answer](http://serverfault.com/a/380079/53133) since it seems to be the approach that least affects the server configuration. Also, I'm sure it will keep running as expected after a server reboot. I'm not so sure about your approach (just killing the `dhcp-client service`). – André Caron Apr 17 '12 at 20:44
  • At the least you can remove resolvconf package, it will not affect the server. Just make sure resolv.conf is properly configured. I am pretty sure resolvconf is at fault. Killing a dhcp client will not affect your server either, it will only prevent it from renewing your dhcp assigned IP when it's time for renewal. I don't think you want a dhcp assigned IP on your server, you want a static IP. – aseq Apr 17 '12 at 20:48
  • No, I don't want/need a static IP. This server is not facing the internet. A public facing reverse proxy forwards traffic to this machine. Everything works fine except the automatic DNS server "update". – André Caron Apr 17 '12 at 21:08
  • You probably want to use a static IP. A server on a LAN still benefits by having a static internal IP. Otherwise it will be changing its IP every so many weeks or months. With obvious consequences. – aseq Apr 17 '12 at 21:15
  • Like I said, the server configuration works and I really don't want to change it. It has been working 24/7 for over two years with reboots in between. The reverse proxy correctly finds this machine by network name (I believe so, it's been a while since I asked the maintainer). I'm having problems with the DNS stuff because the network has very recently been modified and I've been told to use a specific DNS server instead of the other one I was using before. – André Caron Apr 17 '12 at 21:20
  • Whether it works or not doesn't mean it's not incorrectly set up. A server shouldn't have a dhcp assigned IP. Regardless, you need to remove resolvconf and network-manager. Please do that and try again. In addition follow the advise in Kaji's answer. – aseq Apr 17 '12 at 21:25
1

Is your setup running NetworkManager? Consider disabling it if that suits your needs.

UtahJarhead
  • 928
  • 7
  • 14