Skip to content

Commit

Permalink
fix(dns): use 127.0.0.1 if not found dns from /etc/resolv.conf
Browse files Browse the repository at this point in the history
Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
  • Loading branch information
zhaojh329 committed Mar 27, 2024
1 parent aab1e70 commit afda9a0
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions dns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ local function parse_resolvconf()
local conf = {}

if not file.access('/etc/resolv.conf') then
return nil, 'not found "/etc/resolv.conf"'
conf.nameservers = {{ '127.0.0.1', 53 }}
return conf
end

for line in io.lines('/etc/resolv.conf') do
Expand All @@ -59,6 +60,10 @@ local function parse_resolvconf()
end
end

if #nameservers == 0 then
nameservers[#nameservers + 1] = { '127.0.0.1', 53 }
end

conf.nameservers = nameservers

return conf
Expand Down Expand Up @@ -487,10 +492,7 @@ function M.query(qname, opts)
nameservers[#nameservers + 1] = { host, port, socket.is_ipv6_address(host) }
end

local resolvconf, err = parse_resolvconf()
if not resolvconf then
return nil, err
end
local resolvconf = parse_resolvconf()

if #nameservers == 0 then
for _, nameserver in ipairs(resolvconf.nameservers) do
Expand All @@ -506,7 +508,7 @@ function M.query(qname, opts)
qname = qname .. '.' .. resolvconf.search
end

local s, answers, req
local s, answers, req, err

for _, nameserver in ipairs(nameservers) do
local id = get_next_transaction_id()
Expand Down

0 comments on commit afda9a0

Please sign in to comment.