SuffixMatchNode - dynamically add or remove records #17667
|
Hello, is it possible to add and remove domains from the list while using SuffixMatchNode without restarting or reloading dnsdist? I can load from a file at startup using Thank you |
Replies: 4 comments 2 replies
|
It's technically possible but you have to delete and re-create the rule using |
|
To answer the follow-up: yes, that's the workflow, and you can keep using a file. The easy way is to wrap it in a function you can call from the console, so a reload is a single command. Name the rule so In your config: local SUFFIX_FILE = "/etc/dnsdist/suffixes.txt" -- one domain per line
function reloadSuffixRule()
local smn = newSuffixMatchNode()
for line in io.lines(SUFFIX_FILE) do
line = line:gsub("%s+", "")
if line ~= "" and line:sub(1, 1) ~= "#" then
smn:add(line)
end
end
rmRule("suffix-list") -- harmless the first time, when it doesn't exist yet
addAction(SuffixMatchNodeRule(smn, true), RCodeAction(DNSRCode.REFUSED), { name = "suffix-list" })
-- replace RCodeAction(...) with whatever action you use today
end
reloadSuffixRule()Then edit Two things to watch:
If the list changes often or gets large, a key-value store avoids touching the rules at all. A CDB file opened with local kvs = newCDBKVStore("/etc/dnsdist/suffixes.cdb", 30) -- check for changes every 30 s
addAction(KeyValueStoreLookupRule(kvs, KeyValueLookupKeySuffix(0, false)), RCodeAction(DNSRCode.REFUSED))With |
|
@DonQuinleone Could I please ask for some more advice on this topic? I have some CNAME records that I need to pass to pdns-recursor, but it's not working for me when used with CDB. EDIT: It´s working but without a trailing dot (example.com). CDB example: |
|
@vecinohk Apologies - you are right re not using a trailing dot! I’ve corrected the answer above. |
To answer the follow-up: yes, that's the workflow, and you can keep using a file. The easy way is to wrap it in a function you can call from the console, so a reload is a single command. Name the rule so
rmRulecan find it by name instead of by position.In your config: