I have written a very simple (IPv4/IPv6 addresses only) DNS server which can use Lua to determine the IPs to return to the user (It was my big “do cool open source during the pandemic” project). To implement this particular problem, I whipped up this Lua script:
-- This script is to be run by coLunacyDNS
-- This script takes a query like 10.1.2.3.ip4.invalid. and returns the
-- corresponding IP (e.g. 10.1.2.3 here)
-- Change these IPs to the actual IPs the DNS server will run on
bindIp = "127.0.0.1" -- We bind the server to the IP 127.0.0.1
bindIp6 = "::1" -- Localhost for IPv6
function processQuery(Q) -- Called for every DNS query received
if Q.coQtype == 1 then
local query = Q.coQuery
if query:match("^%d+%.%d+%.%d+%.%d+%.ip4%.invalid%.$") then
local ip = query:gsub("%.ip4%.invalid%.$","")
return {co1Type = "A", co1Data = ip}
end
else
return {co1Type = "notThere"}
end
return {co1Type = "notThere"}
end
One will need coLunacyDNS to run this script:
git clone https://github.com/samboy/MaraDNS
cd MaraDNS/deadwood-github/tools/coLunacyDNS
make
sudo cp coLunacyDNS /usr/local/bin
https://github.com/samboy/MaraDNS/blob/master/deadwood-githu...