dns.client.parse_resolv_conf

dns.client

parse_resolv_conf(path) -> config, err

Parse /etc/resolv.conf and return a config table

Reads and parses a resolv.conf file, returning a table suitable for passing to (or merging into) dns.client.new() configuration.

Parsed directives:

Fields are only present in the result when found in the file, allowing the caller to merge with their own defaults. Server entries have no port since standard resolv.conf has no port syntax; the transport default applies.

path defaults to "/etc/resolv.conf".

local dns_client = require("dns.client")

-- Use system resolvers
local sys = dns_client.parse_resolv_conf()
local r = dns_client.new(sys)

-- Merge with overrides
local sys = dns_client.parse_resolv_conf()
sys.timeout = 3
sys.use_tls = true
local r = dns_client.new(sys)