LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
Search this Thread
Old 04-21-2013, 10:39 AM   #1
joncr
Member
 
Registered: Jun 2012
Posts: 74

Rep: Reputation: Disabled
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?
 
Old 04-21-2013, 11:40 AM   #2
mrclisdue
Senior Member
 
Registered: Dec 2005
Distribution: Slackware -current, 14.1
Posts: 1,047

Rep: Reputation: 170Reputation: 170
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,

Last edited by mrclisdue; 04-21-2013 at 11:42 AM.
 
Old 04-21-2013, 11:49 AM   #3
joncr
Member
 
Registered: Jun 2012
Posts: 74

Original Poster
Rep: Reputation: Disabled
Re: chattr -- Right, but, then, what's 'DHCP_KEEPRESOLV[0]="yes"' for? It seems to have been implemented for this specific task.
 
Old 04-21-2013, 12:23 PM   #4
rg3
Member
 
Registered: Jul 2007
Distribution: Slackware Linux
Posts: 509

Rep: Reputation: Disabled
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
 
Old 04-21-2013, 02:48 PM   #5
joncr
Member
 
Registered: Jun 2012
Posts: 74

Original Poster
Rep: Reputation: Disabled
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.

Last edited by joncr; 04-21-2013 at 02:50 PM.
 
Old 04-21-2013, 03:12 PM   #6
TommyC7
Member
 
Registered: Mar 2012
Distribution: Slackware, CentOS, OpenBSD, FreeBSD
Posts: 437

Rep: Reputation: Disabled
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
 
Old 04-21-2013, 03:26 PM   #7
saleo
LQ Newbie
 
Registered: Jan 2012
Location: Serbia
Distribution: Slackware
Posts: 4

Rep: Reputation: Disabled
/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
 
Old 04-21-2013, 03:26 PM   #8
joncr
Member
 
Registered: Jun 2012
Posts: 74

Original Poster
Rep: Reputation: Disabled
Thanks, Tommy. But, as before, the result is a resolv.conf with no name server lines.
 
Old 04-21-2013, 05:41 PM   #9
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 1,437

Rep: Reputation: 599Reputation: 599Reputation: 599Reputation: 599Reputation: 599Reputation: 599
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.

Last edited by rknichols; 04-21-2013 at 05:46 PM.
 
Old 04-21-2013, 05:48 PM   #10
joncr
Member
 
Registered: Jun 2012
Posts: 74

Original Poster
Rep: Reputation: Disabled
I'm not running Network Manager and /etc/dhcp does not exist.
 
Old 04-21-2013, 07:25 PM   #11
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: Carrollton, Texas
Distribution: Slackware64 14.1
Posts: 1,494

Rep: Reputation: 437Reputation: 437Reputation: 437Reputation: 437Reputation: 437
Well, add
Code:
DHCP_DEBUG[0]="yes"
to /etc/rc.d/rc.inet1.conf, restart, and look in the logs.
 
Old 04-22-2013, 08:09 AM   #12
joncr
Member
 
Registered: Jun 2012
Posts: 74

Original Poster
Rep: Reputation: Disabled
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.
 
Old 04-22-2013, 11:34 AM   #13
xflow7
Member
 
Registered: May 2004
Distribution: Slackware
Posts: 158

Rep: Reputation: 21
Quote:
Originally Posted by joncr View Post
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.
 
Old 04-22-2013, 12:34 PM   #14
joncr
Member
 
Registered: Jun 2012
Posts: 74

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by xflow7 View Post
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.
 
Old 04-22-2013, 03:23 PM   #15
rg3
Member
 
Registered: Jul 2007
Distribution: Slackware Linux
Posts: 509

Rep: Reputation: Disabled
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.
 
  


Reply

Tags
dns, nameservers, network-manager, resolvconf


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
i need to keep nwam from changing resolv.conf ( osol 2009.06 & OpenDNS nameservers ) joe262 Solaris / OpenSolaris 2 07-02-2009 12:42 PM
How to re-invoke dhcpd after changes were made to dhcpd.conf file. Azazwa Linux - Newbie 3 03-30-2009 04:44 AM
How to change nameservers WITHOUT editing resolv.conf??? zeeple Linux - Newbie 3 12-02-2008 01:29 PM
DNS Hosts.conf or resolv.conf problem mac_casey Suse/Novell 0 03-26-2006 09:21 AM
dhcpd subnet declaration problems in dhcpd.conf vcrispo Linux - Networking 6 07-15-2005 10:32 AM


All times are GMT -5. The time now is 01:51 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration