Skip to content

lua-resty-dns - Lua DNS resolver for the ngx_lua based on the cosocket API

Notifications You must be signed in to change notification settings

weihaitong/lua-resty-dns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 

Repository files navigation

Name

#support edns-client-subnet

Synopsis

    lua_package_path "/path/to/lua-resty-dns/lib/?.lua;;";

    server {
        location = /dns {
            content_by_lua '
                local resolver = require "resty.dns.resolver"
                local r, err = resolver:new{
                    nameservers = {"8.8.8.8", {"8.8.4.4", 53} },
                    retrans = 5,  -- 5 retransmissions on receive timeout
                    timeout = 2000,  -- 2 sec
                }

                if not r then
                    ngx.say("failed to instantiate the resolver: ", err)
                    return
                end

       		--<modify> local answers, err = r:query("www.google.com")
		local answers, err = r:query("www.google.com", {client = client_ip})
                if not answers then
                    ngx.say("failed to query the DNS server: ", err)
                    return
                end

                if answers.errcode then
                    ngx.say("server returned error code: ", answers.errcode,
                            ": ", answers.errstr)
                end

                for i, ans in ipairs(answers) do
                    ngx.say(ans.name, " ", ans.address or ans.cname,
                            " type:", ans.type, " class:", ans.class,
                            " ttl:", ans.ttl)
                end
            ';
        }
    }

see Also

Back to TOC

About

lua-resty-dns - Lua DNS resolver for the ngx_lua based on the cosocket API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages