Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Override DNS Servers for DHCP Connection
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
wswartzendruber
Veteran
Veteran


Joined: 23 Mar 2004
Posts: 1217
Location: Jefferson, USA

PostPosted: Wed Jan 25, 2012 4:57 am    Post subject: Override DNS Servers for DHCP Connection Reply with quote

I have eth0 setup in /etc/conf.d/net to take DHCP. I want to manually specify DNS, though, and dhcpd seems to overwrite /etc/resolv.conf. Interestingly, dns_servers_eth0 seems to have no effect.
Back to top
View user's profile Send private message
palmer
Guru
Guru


Joined: 17 Nov 2004
Posts: 321
Location: Berkeley, CA

PostPosted: Wed Jan 25, 2012 5:12 am    Post subject: Reply with quote

I have a few ideas, one of which is bound to work at least a little
  • You can try adding the DNS entries you want to /etc/resolv.conf.head (or /etc/resolv.conf.tail), which should get prepended (or appended) to /etc/resolv.conf every time it is updated.
  • If you're running dhcpcd, you can pass "-C resolv.conf" to stop it from overwriting /etc/resolv.conf (you can probably pass this option in a config file somewhere, maybe /etc/conf.d/net?) and then manage /etc/resolv.conf yourself.
  • Try modifying the scripts in /lib64/dhcpcd/dhcpcd-hooks/ to fit whatever you want them to do.
  • Have your DHCP server pass the DNS server IP to use (I use dnsmasq for this).

I would recommend the dnsmasq method, as it works for all machines on your network. This also has the benefit of acting as a caching DNS server which can make browsing feel a lot snappier.
Back to top
View user's profile Send private message
MarkMan
n00b
n00b


Joined: 01 Feb 2011
Posts: 14

PostPosted: Wed Mar 21, 2012 12:34 am    Post subject: Reply with quote

If you are looking to keep /etc/resolv.conf file structure, I would recommend that you set the immutable flag to the file by doing:

# chattr +i /etc/resolv.conf

That would prevent your /etc/resolv.conf file from being modified by you or any other daemons. If you need to modify resolv.conf file content, you will need to unset the immutable flag by:

# chattr -i /etc/resolv.conf
Back to top
View user's profile Send private message
jathlon
Tux's lil' helper
Tux's lil' helper


Joined: 26 Sep 2006
Posts: 88
Location: Canada

PostPosted: Wed Mar 21, 2012 1:25 am    Post subject: Reply with quote

I do part of it in /etc/dhcpcd.conf.

Part of the original unedited /etc/dhcpcd.conf
Code:

# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes


Remove the "domain_name_servers" from the option list.

Then just to be on the safe side I use the /etc/resolv.conf.tail file to make sure that the dns server/servers I want are added to the file every time /etc/init.d/dhcpcd is run.

I classify this as one of those "It Works For Me" * things. YMMV :)


joe

*IWFM in my carefully crafted, fragile little enviroment.
Back to top
View user's profile Send private message
hnaparst
Apprentice
Apprentice


Joined: 27 Jul 2005
Posts: 215
Location: Hertfordshire, UK

PostPosted: Sun Aug 25, 2013 8:42 am    Post subject: Reply with quote

For me, neither dhcpcd.conf modifications nor resolv.conf.tail had any effect.
The solution for me was setting the following in /etc/conf.d/net

Code:
dns_domain= cheap-domains-r-us.com
dns_servers="8.8.8.8 8.8.4.4"
dhcp="nodns"

_________________
Harold Naparst
Back to top
View user's profile Send private message
hika
Apprentice
Apprentice


Joined: 13 Mar 2009
Posts: 220
Location: Utrecht

PostPosted: Tue Aug 27, 2013 1:43 am    Post subject: Reply with quote

You can put a file resolve.conf.head or resolve.conf.tail in /etc those will be prepended and/or appended to resolve.conf.
I use resolve.conf.head to put the dns server on my laptop ahead of local ones.

resolve.conf.head
Code:
domain pc-asus.dkw
nameserver 127.0.0.1


It works with me
Back to top
View user's profile Send private message
ddriver
n00b
n00b


Joined: 24 Feb 2005
Posts: 61

PostPosted: Mon Oct 21, 2013 10:15 pm    Post subject: Reply with quote

hnaparst wrote:
For me, neither dhcpcd.conf modifications nor resolv.conf.tail had any effect.
The solution for me was setting the following in /etc/conf.d/net

Code:
dns_domain= cheap-domains-r-us.com
dns_servers="8.8.8.8 8.8.4.4"
dhcp="nodns"


I came here tonight looking for an answer to the same question, and this was the perfect answer. Thank you.
Back to top
View user's profile Send private message
Gentree
Watchman
Watchman


Joined: 01 Jul 2003
Posts: 5227
Location: France, Old Europe

PostPosted: Sun Oct 27, 2013 10:17 am    Post subject: Reply with quote

I got around my resolv.conf getting dumped on by adding the following to /etc/conf.d/net

Code:
dhcpcd_eth0=" -C resolv.conf"


This probably needs to be repeated for any interface you don't want to dump on resolv.conf so some of the above may be more reliable in the case of a new interface happening by. Like an extra wifi for example.

8)
_________________
Linux, because I'd rather own a free OS than steal one that's not worth paying for.

AthlonXP-M on A7N8X @ 2.6/2.4GHz (winter/summer)
2.6.32-hh1 : portage ~x86
Back to top
View user's profile Send private message
UberLord
Retired Dev
Retired Dev


Joined: 18 Sep 2003
Posts: 6336
Location: Blighty

PostPosted: Sun Oct 27, 2013 11:45 am    Post subject: Reply with quote

Or, dare I say it, add it to /etc/dhcpcd.conf in the top section and BOOM - applies to all interfaces.
_________________
When baselayout tells you to update config files or things break WE REALLY DO MEAN IT

Please add SOLVED to the thread title if your issue has been
Strip comments from configs please
Back to top
View user's profile Send private message
Gentree
Watchman
Watchman


Joined: 01 Jul 2003
Posts: 5227
Location: France, Old Europe

PostPosted: Sun Oct 27, 2013 2:03 pm    Post subject: Reply with quote

man dhcpd:

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

man dhcpcd.conf

Quote:
Most of the options found in dhcpcd( 8 ) can be used here.



So it looks like Uber is suggesting this single line at the top of /etc/dhcpcd.conf
Code:
# A sample configuration for dhcpcd.
# See dhcpcd.conf(5) for details.

-C resolv.conf


_________________
Linux, because I'd rather own a free OS than steal one that's not worth paying for.

AthlonXP-M on A7N8X @ 2.6/2.4GHz (winter/summer)
2.6.32-hh1 : portage ~x86
Back to top
View user's profile Send private message
Gentree
Watchman
Watchman


Joined: 01 Jul 2003
Posts: 5227
Location: France, Old Europe

PostPosted: Sun Oct 27, 2013 2:32 pm    Post subject: Reply with quote

Dare I ask which "it" you are referring to?


Gentree wrote:
man dhcpd:

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

man dhcpcd.conf

Quote:
Most of the options found in dhcpcd( 8 ) can be used here.



So it looks like Uber is suggesting this single line at the top of /etc/dhcpcd.conf
Code:
# A sample configuration for dhcpcd.
# See dhcpcd.conf(5) for details.

-C resolv.conf



Well, that gets spat out , so I guess not.

Perhaps Uber can be a bit more informative that "it". 8)
_________________
Linux, because I'd rather own a free OS than steal one that's not worth paying for.

AthlonXP-M on A7N8X @ 2.6/2.4GHz (winter/summer)
2.6.32-hh1 : portage ~x86
Back to top
View user's profile Send private message
desultory
Administrator
Administrator


Joined: 04 Nov 2005
Posts: 7820

PostPosted: Mon Oct 28, 2013 2:54 am    Post subject: Reply with quote

s/-C/C/
Or, more legibly:
s/-C/nohook/
Back to top
View user's profile Send private message
Gentree
Watchman
Watchman


Joined: 01 Jul 2003
Posts: 5227
Location: France, Old Europe

PostPosted: Mon Oct 28, 2013 5:39 pm    Post subject: Reply with quote

I now have

Code:
# dhcpd options (without leading "-")
C resolv.conf


at the top of /etc/dhcpcd.conf

but I see something like "dhcpcd unknown option -- C flash past during boot.

No trace of this anywhere in dmesg or /var/log/messages

caught it with scroll lock:

Code:
dhcpcd unknown option -- C


Note space before C.


OH, BTW none of that works either, resolv.conf is still getting dumped on by dhcp :x
_________________
Linux, because I'd rather own a free OS than steal one that's not worth paying for.

AthlonXP-M on A7N8X @ 2.6/2.4GHz (winter/summer)
2.6.32-hh1 : portage ~x86
Back to top
View user's profile Send private message
Gentree
Watchman
Watchman


Joined: 01 Jul 2003
Posts: 5227
Location: France, Old Europe

PostPosted: Mon Oct 28, 2013 6:21 pm    Post subject: Reply with quote

Ok the following does work:
Code:

# dhcpd options (without leading "-")
nohook resolv.conf


It seems these options get passed with "--" pre-pended so the short forms don't work.


desultory
PostPosted: Mon Oct 28, 2013 3:54 am Post subject:
s/-C/C/ # wrong
Or, more legibly:
s/-C/nohook/ # correct


UberLord
PostPosted: Sun Oct 27, 2013 12:45 pm Post subject:
Or, dare I say it, add it to /etc/dhcpcd.conf in the top section and BOOM - applies to all interfaces.

# dare I say it, terse but wrong.
_________________
Linux, because I'd rather own a free OS than steal one that's not worth paying for.

AthlonXP-M on A7N8X @ 2.6/2.4GHz (winter/summer)
2.6.32-hh1 : portage ~x86
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum