5

Following the Debian NetworkConfiguration wiki, I've been trying to setup static OpenNIC DNS with no success. The first thing I tried was directly editing /etc/resolv.conf, but it keeps getting overwritten. The wiki page lists three possible sources of the overwrite:

  1. The resolvconf program
  2. The network-manager daemon
  3. DHCP clients
$ apt-cache policy resolvconf
resolvconf:
  Installed: (none)
  Candidate: 1.76.1
  Version table:
     1.76.1 0
        500 http://ftp.us.debian.org/debian/ jessie/main amd64 Packages
$ apt-cache policy network-manager
network-manager:
  Installed: (none)
  Candidate: 0.9.10.0-7
  Version table:
     0.9.10.0-7 0
        500 http://ftp.us.debian.org/debian/ jessie/main amd64 Packages

Considering I don't have resolvconf or network-manager installed, we can assume the source is a DHCP client. I'm using wicd as an alternative to network-manager, but setting up static dns in the wicd-gtk properties doesn't work. Thus, I edited /etc/dhcp/dhclient.conf by adding supersede domain-name-servers 50.116.40.226;, but my /etc/resolv.conf is still:

$ cat /etc/resolv.conf
nameserver 2001:558:feed::2
nameserver 2001:558:feed::1

What is the hell is going on here? Should I install resolvconf to see if it will work? Should I give up on wicd and install network-manager?

  • It's probably a bug in dhclient, which i also ran into. It ignores the supersede. I ended up making /etc/resolv.conf immutable with chattr. But i'm interested in a permanent solution too. – ctrl-d Dec 14 '15 at 23:50
  • Is /etc/resolv.conf a symbolic link to something like /var/cache/resolv.conf.dhcp? If so, break the link and re-create /etc/resolv.conf as a "real" file with your required content. – roaima Dec 14 '15 at 23:53
  • @ctrl-d Bravo, sudo sh -c 'printf "name server 169.57.14.220\nnameserver 190.10.8.128\n" > /etc/resolv.conf' && sudo chattr +i /etc/resolv.conf works! Post an answer along the same lines, and I'll accept it – lscstu22 Dec 15 '15 at 0:22
  • You're welcome. Good that it works for you too. – ctrl-d Dec 15 '15 at 0:33
  • 1
    What version of Debian do you use? If this is a recent one, you have systemd on it, and it overwrites /etc/resolv.conf on networl changes. – Patrick Mevzek Mar 8 '18 at 0:50
-1

Use the following workaround to prevent the dhcp client from updating your carefully crafted /etc/resolv.conf:

# chattr +i /etc/resolv.conf
  • I'd like to add I had to combine the editing and chattr commands into one with && for this to work since /etc/resolv.conf was being overwritten so quickly. Check out the question comments above. – lscstu22 Dec 15 '15 at 0:58
  • Oh really? That was not needed in my case. When you don't run dhclient, nothing will happen to the file. But for completeness, now it's under the answer just in case. – ctrl-d Dec 15 '15 at 1:02
  • I just put in: nameserver 127.0.0.1 and chattr-ed it. – ctrl-d Dec 15 '15 at 1:05
1
+50

I think that your DHCP server sends unsolicited responses, so your resolv.conf was overwritten also if you set the supersede parameter. Adding the +i attr may be a solution but requires that you manually unset and re set it if you have to do some changes.

You can, indeed, write some scripts on the client side (see man 8 dhclient-script).

This topic is also explained in debian wiki:

Another approach makes use of dhclient-script's hook scripts. According to dhclient-script(8):

When it starts, the client script first defines a shell function, make_resolv_conf , which is later used to create the /etc/resolv.conf file. To override the default behaviour, redefine this function in the enter hook script. Therefore, we can stop dhclient from overwriting resolv.conf by doing the following:

echo 'make_resolv_conf() { :; }' > /etc/dhcp/dhclient-enter-hooks.d/leave_my_resolv_conf_alone
chmod 755 /etc/dhcp/dhclient-enter-hooks.d/leave_my_resolv_conf_alone

The execute bit is required because dhclient-script uses run-parts(8) to decide which files to read. For that same reason, the filename must not contain anything but letters, digits, underscores and hyphens.

0

by the way things are not going well at all, it's not even a friend, but you should see it well before you leave, thus applying "chattr + i" files to the system, I think we should look for a solution to the problem that sometimes be something so simple that is in our face and we can not fill because we are nervous wanting to impose our will on the system, sometimes a little script even works miracles when well executed in the network, but apparently you do not want this and by the way is not or is studying to be a systems administrator, sorry! But if you'd rather get nervous and perform these nonsense tricks of this kind on the system okay after all, it's not on my system, sorry to leave it you angry at that! Instead of doing this! to use the 'chattr' command configure, edit the 'interfaces' file, which is usually in the /etc/network/ folder and add/change the dns-nameserver options with the nameserver ip you want. if these options are not in the file you can add them as small examples:

-Sample: just edit the "/etc/network/interfaces" file this way.

   auto lo
   iface lo inet loopback
   iface lo inet6 loopback

   iface eth0 inet dhcp <= Here would be for DHCP devices.
   iface eth0 init 192.168.1.2 <= Here your fixed IP on the network.
   iface eth0 inet6 auto <= Here you define your IPv6 automatically.

   dns-nameserver 192.168.1.1 <= Your IP address here.
   dns-nameserver 8.8.8.8
   dns-nameserver 8.8.4.4

-Save the file and reboot the network ...

In your case you just want to set the IP address of the servers, set only the following to the end of the interfaces file.

   dns-nameserver 8.8.4.4
   dns-nameserver 8.8.8.8

Here is an example that is used here, only does not use DHCP should use the IP automatically defined by the router that changes every boot on the network system.

    auto lo
    iface lo inet loopback
    iface lo inet6 loopback
    iface eth0 inet static

            address 192.168.1.4/24
            netmask 255.255.255.0
            gateway 192.168.1.1

   dns-nameserver 192.168.1.4
   dns-nameserver 8.8.4.4
   dns-nameserver 8.8.8.8

-Here just a little sample for you verify better to understand.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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