View previous topic :: View next topic |
Author |
Message |
wswartzendruber Veteran
Joined: 23 Mar 2004 Posts: 1261 Location: Idaho, USA
|
Posted: Wed Jan 25, 2012 4:57 am Post subject: Override DNS Servers for DHCP Connection |
|
|
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 |
|
|
palmer Guru
Joined: 17 Nov 2004 Posts: 322 Location: Berkeley, CA
|
Posted: Wed Jan 25, 2012 5:12 am Post subject: |
|
|
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 |
|
|
MarkYork n00b
Joined: 01 Feb 2011 Posts: 20
|
Posted: Wed Mar 21, 2012 12:34 am Post subject: |
|
|
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 |
|
|
jathlon Tux's lil' helper
Joined: 26 Sep 2006 Posts: 89 Location: Canada
|
Posted: Wed Mar 21, 2012 1:25 am Post subject: |
|
|
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 |
|
|
ycUygB1 Apprentice
Joined: 27 Jul 2005 Posts: 276 Location: Portland, Oregon
|
Posted: Sun Aug 25, 2013 8:42 am Post subject: |
|
|
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"
|
|
|
Back to top |
|
|
hika Apprentice
Joined: 13 Mar 2009 Posts: 234 Location: Utrecht
|
Posted: Tue Aug 27, 2013 1:43 am Post subject: |
|
|
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 |
|
|
ddriver n00b
Joined: 24 Feb 2005 Posts: 67
|
Posted: Mon Oct 21, 2013 10:15 pm Post subject: |
|
|
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 |
|
|
Gentree Watchman
Joined: 01 Jul 2003 Posts: 5350 Location: France, Old Europe
|
Posted: Sun Oct 27, 2013 10:17 am Post subject: |
|
|
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.
_________________ Linux, because I'd rather own a free OS than steal one that's not worth paying for.
Gentoo because I'm a masochist
AthlonXP-M on A7N8X. Portage ~x86 |
|
Back to top |
|
|
UberLord Retired Dev
Joined: 18 Sep 2003 Posts: 6835 Location: Blighty
|
|
Back to top |
|
|
Gentree Watchman
Joined: 01 Jul 2003 Posts: 5350 Location: France, Old Europe
|
Posted: Sun Oct 27, 2013 2:03 pm Post subject: |
|
|
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.
Gentoo because I'm a masochist
AthlonXP-M on A7N8X. Portage ~x86 |
|
Back to top |
|
|
Gentree Watchman
Joined: 01 Jul 2003 Posts: 5350 Location: France, Old Europe
|
Posted: Sun Oct 27, 2013 2:32 pm Post subject: |
|
|
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". _________________ Linux, because I'd rather own a free OS than steal one that's not worth paying for.
Gentoo because I'm a masochist
AthlonXP-M on A7N8X. Portage ~x86 |
|
Back to top |
|
|
desultory Bodhisattva
Joined: 04 Nov 2005 Posts: 9410
|
Posted: Mon Oct 28, 2013 2:54 am Post subject: |
|
|
s/-C/C/
Or, more legibly:
s/-C/nohook/ |
|
Back to top |
|
|
Gentree Watchman
Joined: 01 Jul 2003 Posts: 5350 Location: France, Old Europe
|
Posted: Mon Oct 28, 2013 5:39 pm Post subject: |
|
|
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 _________________ Linux, because I'd rather own a free OS than steal one that's not worth paying for.
Gentoo because I'm a masochist
AthlonXP-M on A7N8X. Portage ~x86 |
|
Back to top |
|
|
Gentree Watchman
Joined: 01 Jul 2003 Posts: 5350 Location: France, Old Europe
|
Posted: Mon Oct 28, 2013 6:21 pm Post subject: |
|
|
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.
Gentoo because I'm a masochist
AthlonXP-M on A7N8X. Portage ~x86 |
|
Back to top |
|
|
orionbelt Apprentice
Joined: 05 Apr 2006 Posts: 178
|
Posted: Mon Sep 26, 2016 3:57 pm Post subject: |
|
|
I have a similar, though not identical, problem. My /etc/conf.d/net is empty, so DHCP (udhcpc) is used by default. However, i now need to add some options to /etc/resolv.conf, which however is overwritten. As per net.example documentation, i put this single line in my /etc/conf.d/net:
Code: | dns_options="rotate single-request-reopen" | Alas, its has no effect.
Using /etc/resolv.conf.tail file did not help either, but i would prefer the /etc/conf.d/net option anyway.
Could someone explain why it doesn't work and, ideally, how to make it work? |
|
Back to top |
|
|
Logicien Veteran
Joined: 16 Sep 2005 Posts: 1555 Location: Montréal
|
Posted: Mon Sep 26, 2016 5:00 pm Post subject: |
|
|
For Dhcpcd not touch /etc/resolv.conf, domain_name_servers must be remove from any option containing it and the line
must be in /etc/dhcpcd.conf. To configure the dhcp request per interface the line master must be at the top of the file. Than you can configure Dhcpcd per interface. For example
Code: | master
interface eth0
dhcpcd
nohook wpa_supplicant
option domain_name_servers
interface wlan0
dhcpcd
env wpa_supplicant_driver=nl80211
nohook resolv.conf |
_________________ Paul |
|
Back to top |
|
|
orionbelt Apprentice
Joined: 05 Apr 2006 Posts: 178
|
Posted: Mon Sep 26, 2016 6:21 pm Post subject: |
|
|
Thanks for the comment. As i said, i did not touch /etc/resolv.conf, and i am not using dhcpcd but udhcpc.
The only file i touched was /etc/conf.d/net. As far as i can tell, according to the documentation it was supposed to work but it didn't... |
|
Back to top |
|
|
|