Resolv.conf

OpenBSD's name lookup relies on resolv.conf(5) to tell it which nameservers to query.

Check Resolvd

WARNING: As of OpenBSD 6.9, resolvd is enabled by default. This may cause nameservers obtained by DHCP and other components to overwrite values you specify in /etc/resolv.conf.

Change Default Nameserver

Suppose we want the system resolver to use the nameserver 198.51.100.1. Then, we can fill /etc/resolv.conf with our own values:

lookup file bind
nameserver 198.51.100.1

The first line tells the system to lookup the file /etc/hosts (the hosts file) first, then query the domain name server.

Note: BIND was historically the default nameserver for Berkeley, although it is no longer included in OpenBSD.

The next line tells the system to query the nameserver 198.51.100.1.

Now, when you use the command host, dig, or nslookup?, the nameserver 198.51.100.1 will be used by default.

$ dig example.com
...
;; ANSWER SECTION:
example.com.            3600    IN      A       93.184.215.14

;; Query time: 56 msec
;; SERVER: 198.51.100.1#53(198.51.100.1)
;; WHEN: Sat Dec 14 00:37:55 CST 2024
;; MSG SIZE  rcvd: 56

Prefer IPv6

If we want the resolver to prefer IPv6 over IPv4, we add this line to /etc/resolv.conf:

family inet6 inet4

So far, the resolv.conf(5) file might look like:

lookup file bind
family inet6 inet4
nameserver 198.51.100.1

Use local caching nameserver

Suppose we want to run our own caching nameserver with unwind or unbound. In that case, edit /etc/resolv.conf:

lookup file bind
family inet6 inet4
nameserver 127.0.0.1

Stale DNS records

If DNS records have changed, the nameserver in resolv.conf may have old cached records. DNS relies on the Time-to-Live (TTL) values to indicate how long a result should be cached. If the values have changed recently, you may want to manually flush the nameserver's old DNS cache.

How to do this depends on which nameservers you have specified in resolv.conf.

If you use your own local caching DNS server with unwind or unbound, you will have far more control over your DNS lookup. These two servers can also help prevent censorship and privacy issues. Consult those guides for how to flush stale DNS records.