• We should now be fully online following an overnight outage. Apologies for any inconvenience, we do not expect there to be any further issues.

Linux - how do I specify an additional nameserver while using dhcp?

Flatline

Golden Member
Jun 28, 2001
1,248
0
0
This one is a bit sticky...I want to specify an additional nameserver (my isp's nameservers sometimes take as much as 20 seconds to find a site), but I need to use dhcp. The problem is that when I add a nameserver to /etc/resolv.conf it disappears when networking is restarted because the dhcp-defined values override my manually inputted settings. Does anyone know of a workaround for this or am I just stuck editing resolv.conf every time I boot my machine?

Not that it makes much of a difference (because as far as I know, all linux boxes do this), but I am running Debian on the machine in question.
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Look for a configuration file for the dhcp client. It should allow you some overrides.
 

drag

Elite Member
Jul 4, 2002
8,708
0
0
If that's to complicated, you can do a "wrong" way.

Put in your init scripts somewhere, but after dhcp configures everything:

echo "nameserver ip.address" >> /etc/resolv.conf
echo "nameserver ip.address2" >> /etc/resolv.conf

(or if you want to just erase the original dns server just leave one of those ">" out on the first line.)
 

Flatline

Golden Member
Jun 28, 2001
1,248
0
0
The init script is what I have done; I was hoping that there was a "better" way of doing it simply, but I guess for now I'll just leave it the way it is. Thanks for the help guys! :beer:
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Originally posted by: Flatline
The init script is what I have done; I was hoping that there was a "better" way of doing it simply, but I guess for now I'll just leave it the way it is. Thanks for the help guys! :beer:

If you are using dhclient (written by the ISC), the config file would be /etc/dhclient.conf. If you are using pump or pretty much any other client, I don't know what the file would be. dhclient atleast, has a way to override the settings you get from the dhcp server. Check your manpages.
 

chsh1ca

Golden Member
Feb 17, 2003
1,179
0
0
Actually, the best way is to add a line that adds your nameserver configuration via echo to the /etc/dhcpc/dhcpcd-eth0.exe file. It may say .exe, but it is just a script that gets executed whenever your IP address has changed. By default, it simply echoes that change to logger, but if you append a line like drag showed you to the file, it will automatically do it after every DHCP renewal.

EDIT: This is of course assuming you are using ISC's DHCPCd.
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
I always used dhclient.conf for this. append name-server "foo"; or something like that. Check out the man page for dhclient.conf for the exact name of the setting.
 

NuclearFusi0n

Diamond Member
Jul 2, 2001
7,028
0
0
from the manpage for dhcpcd:
-R
Prevents dhcpcd from replacing existing /etc/resolv.conf file.

edit the script that calls dhcpcd to get an ip, and edit your /etc/resolv.conf as you see fit. it wont change on a reboot