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: 1261
Location: Idaho, 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: 322
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
MarkYork
n00b
n00b


Joined: 01 Feb 2011
Posts: 20

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: 89
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
ycUygB1
Apprentice
Apprentice


Joined: 27 Jul 2005
Posts: 276
Location: Portland, Oregon

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"
Back to top
View user's profile Send private message
hika
Apprentice
Apprentice


Joined: 13 Mar 2009
Posts: 234
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: 67

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: 5350
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.
Gentoo because I'm a masochist
AthlonXP-M on A7N8X. Portage ~x86
Back to top
View user's profile Send private message
UberLord
Retired Dev
Retired Dev


Joined: 18 Sep 2003
Posts: 6835
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.
_________________
Use dhcpcd for all your automated network configuration needs
Use dhcpcd-ui (GTK+/Qt) as your System Tray Network tool
Back to top
View user's profile Send private message
Gentree
Watchman
Watchman


Joined: 01 Jul 2003
Posts: 5350
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.
Gentoo because I'm a masochist
AthlonXP-M on A7N8X. Portage ~x86
Back to top
View user's profile Send private message
Gentree
Watchman
Watchman


Joined: 01 Jul 2003
Posts: 5350
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.
Gentoo because I'm a masochist
AthlonXP-M on A7N8X. Portage ~x86
Back to top
View user's profile Send private message
desultory
Bodhisattva
Bodhisattva


Joined: 04 Nov 2005
Posts: 9410

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: 5350
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.
Gentoo because I'm a masochist
AthlonXP-M on A7N8X. Portage ~x86
Back to top
View user's profile Send private message
Gentree
Watchman
Watchman


Joined: 01 Jul 2003
Posts: 5350
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.
Gentoo because I'm a masochist
AthlonXP-M on A7N8X. Portage ~x86
Back to top
View user's profile Send private message
orionbelt
Apprentice
Apprentice


Joined: 05 Apr 2006
Posts: 178

PostPosted: Mon Sep 26, 2016 3:57 pm    Post subject: Reply with quote

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
View user's profile Send private message
Logicien
Veteran
Veteran


Joined: 16 Sep 2005
Posts: 1555
Location: Montréal

PostPosted: Mon Sep 26, 2016 5:00 pm    Post subject: Reply with quote

For Dhcpcd not touch /etc/resolv.conf, domain_name_servers must be remove from any option containing it and the line
Code:
nohook resolv.conf

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
View user's profile Send private message
orionbelt
Apprentice
Apprentice


Joined: 05 Apr 2006
Posts: 178

PostPosted: Mon Sep 26, 2016 6:21 pm    Post subject: Reply with quote

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
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