LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   Need To Keep DHCPD From Deleting Nameservers Specified in Resolv.Conf (http://www.linuxquestions.org/questions/slackware-14/need-to-keep-dhcpd-from-deleting-nameservers-specified-in-resolv-conf-4175459003/)

joncr 04-21-2013 11:39 AM

Need To Keep DHCPD From Deleting Nameservers Specified in Resolv.Conf
 
I'd like to use Google's name servers instead of my ISP's.

I'm on 14 with a wired eth0 connection. It's just dhcpd via netconfig. Network Manager does not run.

When rc.inet1.conf looks like this:

Code:

# Config information for eth0:
IPADDR[0]=""
NETMASK[0]=""
USE_DHCP[0]="yes"
DHCP_HOSTNAME[0]=""
DHCP_KEEPRESOLV[0]="yes"

...and resolv.conf looks like this:

Code:

# Generated by dhcpcd from eth0
# /etc/resolv.conf.head can replace this line
nameserver 8.8.8.8
nameserver 8.8.4.4
# /etc/resolv.conf.tail can replace this line

...and I reboot... resolv.conf then looks like this:

Code:

# Generated by dhcpcd from eth0
# /etc/resolv.conf.head can replace this line
# /etc/resolv.conf.tail can replace this line

And, of course, I no longer can resolve anything.

"man rc.inet1.conf" says:

Code:

DHCP_KEEPRESOLV[0]="yes" #  If you do not want `/etc/resolv.conf' over-written by the DHCP client
I know I can do this with Network Manager, and I probably should, but can I specify nameservers in resolv.conf and keep dhcpd from overriding them without using Network Manager?

mrclisdue 04-21-2013 12:40 PM

As root, issue this command:

Code:

$ chattr -i /etc/resolv.conf
see man chattr for more info, but basically you're setting the file's immutable bit, meaning the file can't be overwritten, even by root, until you change its bit back....


cheers,

joncr 04-21-2013 12:49 PM

Re: chattr -- Right, but, then, what's 'DHCP_KEEPRESOLV[0]="yes"' for? It seems to have been implemented for this specific task.

rg3 04-21-2013 01:23 PM

When DHCP_KEEPRESOLV[0] is set to "yes", the option "-C resolv.conf" is passed to dhcpcd in order to prevent it from running the /lib/dhcpcd/dhcpcd-hooks/20-resolv.conf hook. You can see this in the rc.inet1 script.

You can verify the proper option was passed to dhcpcd in a running system by using something like:

Code:

xxd /proc/`pgrep dhcpcd`/cmdline

joncr 04-21-2013 03:48 PM

Couldn't get it working, and would rather avoid the chattr approach, so I put the Google name servers in /etc/resolv.conf.head and they are prepended to resolv.conf.

Still curious why 'DHCP_KEEPRESOLV[0]="yes"'didn't work as advertised.

TommyC7 04-21-2013 04:12 PM

Hi there,

I haven't run into this situation myself, but as rg3 said, the option just passes "-C resolv.conf" to dhcpcd. However, dhcpcd also has a configuration file that you can edit.
Code:

$ tail -n 3 /etc/dhcpcd.conf
# A hook script is provided to lookup the hostname if not set by the DHCP
# server, but it should not be run by default.
nohook resolv.conf, lookup-hostname

Through dhcpcd's configuration file the above basically asks dhcpcd to pass --no-hook (aka -C) for resolv.conf and lookup-hostname (notice the comma for separation). The default configuration for dhcpcd only does that for lookup-hostname:
Code:

$ tail -n 3 /etc/dhcpcd.conf.new
# A hook script is provided to lookup the hostname if not set by the DHCP
# server, but it should not be run by default.
nohook lookup-hostname


saleo 04-21-2013 04:26 PM

/etc/resolv.conf
Code:

# Generated by dhcpcd from eth0
/etc/resolv.conf.head can replace this line
# /etc/resolv.conf.tail can replace this line

/etc/resolv.conf.head
Code:

nameserver 8.8.8.8
nameserver 8.8.4.4


joncr 04-21-2013 04:26 PM

Thanks, Tommy. But, as before, the result is a resolv.conf with no name server lines.

rknichols 04-21-2013 06:41 PM

Is this an issue with dhcpd, or is it really a dhclient issue?

NetworkManager generates its own dhclient config file for each dhclient invocation. The global /etc/dhcp/dhclient.conf file is ignored. You can see this with ps:
Code:

$ ps fww$(pidof dhclient)
  PID TTY      STAT  TIME COMMAND
 9801 ?        S      0:00 /sbin/dhclient -d -4 -sf /usr/libexec/nm-dhcp-client.action -pf /var/run/dhclient-eth1.pid -lf /var/lib/dhclient/dhclient-9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04-eth1.lease -cf /var/run/nm-dhclient-eth1.conf eth1

Note the part in red at the end of that long line.

If you want to add or override options for dhclient, you need to put those (and only the options you want to change) in /etc/dhcp/dhclient-<device>.conf (e.g., /etc/dhcp/dhclient-eth0.conf). Personally, I've always used the "prepend domain-name-servers ..." option there.

joncr 04-21-2013 06:48 PM

I'm not running Network Manager and /etc/dhcp does not exist.

Richard Cranium 04-21-2013 08:25 PM

Well, add
Code:

DHCP_DEBUG[0]="yes"
to /etc/rc.d/rc.inet1.conf, restart, and look in the logs.

joncr 04-22-2013 09:09 AM

Code:

DHCP_DEBUG[0]="yes"
Ah. Yes.

What I notice is that the "-C" option is passed to dhcpcd:

Code:

/etc/rc.d/rc.inet1:  /sbin/dhcpcd -t 10  -C resolv.conf -d eth0
Dhcpcd's man says the timeout defaults to 30, not 10. Setting it to 30 in rc.inet1.conf had no affect, though.

I think I'll let this simmer for a while, since I have what I want via resolv.conf.head. Thanks all for the advice.

xflow7 04-22-2013 12:34 PM

Quote:

Originally Posted by joncr (Post 4935952)
Couldn't get it working, and would rather avoid the chattr approach, so I put the Google name servers in /etc/resolv.conf.head and they are prepended to resolv.conf.

Still curious why 'DHCP_KEEPRESOLV[0]="yes"'didn't work as advertised.

The only manpage for dhcpcd I found which mentions a -C option is here: http://roy.marples.name/man/html8/dhcpcd.html

Interestingly, it says that the argument can be the actual name or prefixed by 2 digits and optionally with .sh extension. If you take that literally, then '-C resolv.conf' wouldn't actually exclude .../20-resolv.conf because of the hyphen (notwithstanding the example in the manpage that uses '-C resolv.conf'). I do wonder if that's why DHCP_KEEPRESOLV[i] doesn't appear to be respected in this case.

joncr 04-22-2013 01:34 PM

Quote:

Originally Posted by xflow7 (Post 4936584)
The only manpage for dhcpcd I found which mentions a -C option is here: http://roy.marples.name/man/html8/dhcpcd.html

"man dhcpcd" here displays this:

Code:

-C, --nohook script
        Don't run this hook script.  Matches full name, or prefixed with
        2 numbers optionally ending with .sh.

        So to stop dhcpcd from touching your DNS or MTU settings you
        would do:-
              dhcpcd -C resolv.conf -C mtu eth0

'Tis curious.

rg3 04-22-2013 04:23 PM

It's supposed to work the way it's called. Again, you could run this:

Code:

xxd /proc/`pgrep dhcpcd`/cmdline
This will tell you if the current running instance of dhcpcd has been called with the proper arguments. If rc.inet1 calls it correctly, you could at least check if something else is stopping it and launching it again without the -C option.


All times are GMT -5. The time now is 08:04 AM.