Setting DNS servers for a NIC

  • Thread starter Deleted member 67029
  • Start date
D

Deleted member 67029

Guest
Hey all

I'm trying to set DNS servers for a NIC in BSD 12.2-RELEASE. I checked for instructions on how to do in the handbook under section 12.5.2. 'Configuring the Network Card' but I couldn't find anything.

How can I go about setting DNS servers for a NIC?
 
I think I have figured out how to do it. Section 12.5.2 also states:

If there is no DHCP server and access to the Internet is needed, manually configure the default gateway and the nameserver:
# sysrc defaultrouter="your_default_router"
# echo 'nameserver your_DNS_server' >> /etc/resolv.conf


How would I go about adding a second nameserver though?
 
OP, "static ip address for an interface" is what you needed to lookup.

As pointed out by covacat resolv.conf settings are system-wide, not per interface.
If you want to add another DNS server to your system, simply add another nameserver line to /etc/resolv.conf

I believe there are ways (maybe even some ports) that could be used to give different DNS servers based on which interface is active. You see logic like this alot for laptops with wireless and wired interfaces, but that typically is done using DHCP (different DHCP servers, giving different addresses and different DNS servers).

local-unbound (as pointed out by Alain De Vos ) is useful if you want to run a "caching DNS server". If you don't want to do that, but simply go out to say Google or OpenDNS servers you don't need to worry about local-unbound.
 
mer

I already setup a static IP address.

Oh that's interesting about resolv.conf being system wide. I wonder what would have happen if you had two NIC's using DHCP and both giving a different pair of nameservers.

If I add another nameserver to my system, wouldn't adding another nameserver line overwrite the previous line? I thought perhaps maybe a second nameserver is added using a comma to the existing line after the first nameserver?

nameserver 1.2.3.4,5.6.7.8
 
I wonder what would have happen if you had two NIC's using DHCP and both giving a different pair of nameservers.
They'll get flipped back and forth. Just like the default gateway (you can only have one default gateway). The last DHCP accepted response wins.

If I add another nameserver to my system, wouldn't adding another nameserver line overwrite the previous line? I thought perhaps maybe a second nameserver is added using a comma to the existing line after the first nameserver?
Code:
domain example.com
nameserver 1.2.3.4
nameserver 2.3.4.5
nameserver 3.4.5.6
You can have a maximum of 3 servers, you can add more but they'll get ignored (might even generate a warning). See resolv.conf(5).
Code:
     nameserver	 Internet address (in dot notation) of a name server that the
		 resolver should query.	 Up to MAXNS (currently	3) name
		 servers may be	listed,	one per	keyword.  If there are multi-
		 ple servers, the resolver library queries them	in the order
		 listed.  If no	nameserver entries are present,	the default is
		 to use	the name server	on the local machine.  (The algorithm
		 used is to try	a name server, and if the query	times out, try
		 the next, until out of	name servers, then repeat trying all
		 the name servers until	a maximum number of retries are	made).
 
The DNS lookup setting is for all interfaces, starting with /etc/nsswitch.conf.
The interaction with DHCP is not fully clear to me.
Maybe like SirDice says it's something like round-robin.
 
mer

*snipp* I wonder what would have happen if you had two NIC's using DHCP and both giving a different pair of nameservers.

If I add another nameserver to my system, wouldn't adding another nameserver line overwrite the previous line? I thought perhaps maybe a second nameserver is added using a comma to the existing line after the first nameserver?

nameserver 1.2.3.4,5.6.7.8
That's why the others said: For Static IP.
If you have DHCP, your resolv.conf gets "overwritten" with every new boot with a default-version.

I had the same Issue, but DHCP was a must.
The solution was a supersede resp. append entry in /etc/dhclient.conf

EDIT: That was with FreeBSD 12.1
No Idea if they changed anything for 13
 
Oh that's interesting about resolv.conf being system wide. I wonder what would have happen if you had two NIC's using DHCP and both giving a different pair of nameservers.
Giving, so you'd run a DHCP server? Well, nothing special would happen other than one section of your clients using DNS server 'A' whereas the others would use 'B'.

Unless of course you meant getting two different IP addresses. Then once again nothing special would happen; the availabality of the DNS server(s) would depend on your routing table. DNS servers are also used in a "first come, first use" setup, as others mentioned also see the resolv.conf(5) manualpage.

If I add another nameserver to my system, wouldn't adding another nameserver line overwrite the previous line? I thought perhaps maybe a second nameserver is added using a comma to the existing line after the first nameserver?

nameserver 1.2.3.4,5.6.7.8
See the manualpage, that's not how it works.

Also... while you can have multiple DNS servers only one will be used, the rest will act as fallovers. So if the first doesn't respond then the system will use another.

There's really no magic going on here.
 
That's true. resolvconf takes the DHCP DNS setting and writes it in resolv.conf and sometimes even in /var/unbound.
From there it is just like you manually edited resolv.conf.
 
SirDice

Your response confuses me. It looks like you are setting nameservers for a domain? I want to set nameservers for a NIC.


ShelLuser

Which manualpage?
 
Your response confuses me. It looks like you are setting nameservers for a domain? I want to set nameservers for a NIC.
Your machine is part of a (DNS) domain, that's what you typically set in /etc/resolv.conf too. That way you can use "short" names instead of having to use the FQDN. I.e. ping lanmachine1 instead of ping lanmachine1.my.local.network. DNS settings are for the whole system, not per interface.
 
Let me make it perfectly clear then, there are no per interface DNS settings, it is a per machine setting.
 
Thanks but I wasn't wanting to know that either. My question was how to set a second nameserver for a NIC. :)
 
For crying out loud, I wrote that in my post and pointed you to the man page where you can look this up.
 
Sorry SirDic but your post really confuses me. I just wanted to know how to set nameservers for my NIC.
 
Oh now I get it. Cool, thanks.
 
I thought it was per NIC because that is how it is in Windows.
 
It's not on Windows either, you might configure the settings in the configuration panel of TCP/IP of the interface but it's a system-wide change.
 
Back
Top