How to prepend localhost in /etc/resolv.conf on a DNS server

Noris

New Member


Messages: 8

#1
I have setup a DNS server for my department which is running FreeBSD 10.2. It is currently connected to the campus internet and receives its address via dhcp, so /etc/resolv.conf looks like this:

Code:
#Generated by resolvconf
search ttu.edu
nameserver x.x.x.x
nameserver x.x.x.x
The machine is serving DNS from another interface so I need the first nameserver to be 127.0.0.1. Therefore, I put the following in /etc/dhclient.conf:

Code:
prepend domain-name-servers 127.0.0.1;
However, now /etc/resolv.conf gets entirely rewritten and the only thing left is:

Code:
#Generated by resolvconf
nameserver 127.0.0.1
Why did everything else go away and how do I prepend the local DNS server without losing everything else?
 

SirDice

Administrator
Staff member
Administrator
Moderator

Thanks: 6,429
Messages: 27,750

#2
Servers, especially DNS servers, shouldn't use DHCP but static addresses. What if it suddenly receives a different IP address? Then none of your clients would be able to resolve anything.
 
OP
OP
N

Noris

New Member


Messages: 8

#3
Servers, especially DNS servers, shouldn't use DHCP but static addresses. What if it suddenly receives a different IP address? Then none of your clients would be able to resolve anything.
Thank you, but this will not be a problem in my case. Please try to stay on topic.
 

Jeckt

Member

Thanks: 16
Messages: 70

#4
I'm not sure if that's your entire dhclient.conf , but if it is, you're supposed to specify the interface in a block. I've only used supersede not prepend, but this does work for me.
Code:
interface "if_name0" {
     prepend domain-name-servers 127.0.0.1;
}
Where if_name0 is the name of the network interface facing the internet.

I agree with SirDice though. This sounds like you're going to end up with an inconsistent or more likely non functioning dns settings. If you plan on using a caching/resolver like unbound, using the DNS server from the campus servers isn't needed in resolv.conf, it would be specified in the resolver configuration to pass requests along. If you want to add your own local only dns names, unbound (for example) can do that using local-data, then resolving normally otherwise.
 

tingo

Daemon

Thanks: 340
Messages: 1,857

#5
Why did everything else go away and how do I prepend the local DNS server without losing everything else?
When you use DHCP as a client on your machine, it overwrites /etc/resolv.conf.
Unless you create /etc/dhclient-enter-hooks with this content
Code:
root@kg-omni1# more /etc/dhclient-enter-hooks
# avoid overwriting /etc/resolv.conf
add_new_resolv_conf() {
  # We don't want /etc/resolv.conf changed
  # So this is an empty function
  return 0
}
HTH
 
Top