lua-resty-proxydns is a Lua module designed for OpenResty that proxies DNS requests, caches them locally, and allows redirection to specific addresses for predefined domains.
- DNS Proxying: Redirects DNS requests through specified nameservers.
- Local Caching: Caches DNS queries and responses locally to enhance performance.
- Custom Domain Redirection: Redirects predefined domains to specified addresses.
To install this module, you can use the OpenResty Package Manager (opm):
opm get iakuf/lua-resty-proxydnsThis module requires the lua-cjson and lua-resty-openssl libraries to work. Ensure that both libraries are installed and accessible in your OpenResty environment.
You can install lua-cjson using OPM:
opm get ledgetech/lua-cjsonYou can install lua-resty-dns-server using OPM:
opm get selboo/lua-resty-dns-serverYou can install lua-resty-resolver using OPM:
opm get jkeys089/lua-resty-resolverAdd the DNS proxy configuration to your nginx.conf:
stream {
lua_shared_dict dns_cache 10m;
init_by_lua_block {
local dns_proxy = require("resty.proxydns")
dns_proxy:config({
nameservers = {"8.8.8.8", "8.8.4.4"},
retrans = 5,
timeout = 2000,
})
dns_proxy:init_custom_domains("/etc/openresty/domains.txt")
}
server {
listen 53 udp;
content_by_lua_block {
local dns_proxy = require("resty.proxydns")
dns_proxy:run()
}
}
}If you want to customize a specific domain to a specific address, you can directly configure the init_custom_domains with a file path containing the domain and corresponding IP addresses.
dns_proxy:init_custom_domains("/etc/openresty/domains.txt")
Create a domains.txt file in the specified location (/etc/openresty/domains.txt) with the format:
example.com 192.168.1.1
test.com 192.168.1.2Each line contains a domain followed by an IP address to which the domain should be redirected.
To redirect all domains in the DNS to a specific address, you can configure the redirect_all parameter with an address, for example:
dns_proxy:redirect_all("10.10.10.1")You can dynamically adjust this setting. If an empty string is passed, the DNS will resolve normally. Specific sources can be given specific outputs accordingly.
Start your OpenResty server as usual. The DNS proxy will handle requests for the domains specified in domains.txt and cache the DNS queries as configured.
This module is licensed under the MIT License - see the LICENSE file for details.