FreeBSD: Set Primary Nameserver(s) in resolv.conf

I’ve been having trouble with my ISP’s nameserver so I wanted to switch over to Google’s public DNS.

The issue I had was that each time I rebooted my system resolvconf would be provided with my ISP’s nameserver (as part of the DHCP process) and would set this in /etc/resolv.conf. This replaced any changes I made during my last session (as it should).

After a poke around in the man pages resolveconf(8) and resolvconf.conf(5) I found that I could prepend a set of nameservers to my resolv.conf. It would then fall back to any other nameservers provided to resolvconf when required.

This can be done simply by adding the following to /etc/resolvconf.conf (create this if it isn’t there):

# Replace with the ip(s) of your chosen nameserver
name_servers="8.8.8.8 8.8.4.4"

You can then regenerate /etc/resolv.conf using:

$ resolvconf -u

And your /etc/resolv.conf should look something like:

$ cat /etc/resolv.conf
# Generated by resolvconf
search lan
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 192.168.1.254

Enjoy!

References

comments powered by Disqus