Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward DNS Query Based on Specific Answer (Matching IP Address) #114

Open
Ealireza opened this issue Sep 22, 2024 · 3 comments
Open

Forward DNS Query Based on Specific Answer (Matching IP Address) #114

Ealireza opened this issue Sep 22, 2024 · 3 comments

Comments

@Ealireza
Copy link

I need to forward DNS queries to a secondary DNS server if a specific value (IP address) is returned in the DNS response. Specifically, if the answer contains 192.168.1.1, I want the request to be forwarded to 10.10.10.1 for re-resolution.
Expected Behavior:

A user queries for a domain (e.g., dig alibaba.com).
If the result contains the IP address 192.168.1.1, the query should be automatically forwarded to another DNS server (e.g., 10.10.10.1) for further resolution.

Current Attempt:

lua


policy.add(policy.all(function (state, req)
    log("info Policy function triggered")

    -- Get the DNS answer section
    local answer = req:answer()
    if answer then
        for _, record in ipairs(answer) do
            -- Check if the response is an A record and contains the IP 192.168.1.1
            if record.stype == kres.type.A and tostring(record.rdata) == '192.168.1.1' then
                log("info IP is 192.168.1.1, forwarding to 10.10.10.1")
                -- Forward the query to the specified DNS server
                return policy.FORWARD({'10.10.10.1'})
            end
        end
    else
        log("info No answer found")
    end

    return kres.DONE
end), true)

Issue:

The function triggers correctly, but the query is not being forwarded to the specified DNS server when the condition (record.rdata == '192.168.1.1') is met.
Steps to Reproduce:

Add the above Lua code to the Knot Resolver configuration.
Query for a domain (dig alibaba.com).
If the result contains the IP 192.168.1.1, the query should be forwarded, but it does not.

Environment:

Knot Resolver Version: [Include version]
Operating System: [Your OS]
Configuration: [Any relevant additional configuration]

Desired Solution:

I would like the query to forward correctly to 10.10.10.1 whenever the answer contains 192.168.1.1. Any guidance on why the forward might not be triggered or if additional configurations are needed would be appreciated.

@Ealireza Ealireza changed the title If the DNS query result contains a specific value Forward DNS Query Based on Specific Answer (Matching IP Address) Sep 22, 2024
@vcunat
Copy link
Member

vcunat commented Sep 23, 2024

So far we don't have ability to restart the resolution (based on results), and I don't expect it anytime soon, I'm afraid.

@Ealireza
Copy link
Author

do you know any dns solution provide this feature ?

@vcunat
Copy link
Member

vcunat commented Sep 24, 2024

I don't. But it's not like I know such details in many alternatives.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants