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

plugin.cfg:Maybe we need to change order of hosts and template ? #5350

Closed
lixd opened this issue Apr 27, 2022 · 3 comments
Closed

plugin.cfg:Maybe we need to change order of hosts and template ? #5350

lixd opened this issue Apr 27, 2022 · 3 comments
Labels
answered The question has been answered question

Comments

@lixd
Copy link

lixd commented Apr 27, 2022

The priority of domain name resolution set separately is higher than that of generic domain name resolution.

and in this Corefile:

b.com:53 {
    errors
    cache 10
	loadbalance
    hosts {
        1.2.3.4 r1.b.com
        2.3.4.5 r1.b.com
        fallthrough
    }
    template IN A b.com {
        match .*\.b\.com
        answer "{{ .Name }} 60 IN A 11.22.33.44"
        answer "{{ .Name }} 60 IN A 22.33.44.55"
        fallthrough
    }

I resolve r1.b.com, which will response 11.22.33.44 and 22.33.44.55. in fact I need to get 1.2.3.4 and 2.3.4.5.
I found the reason is plugins order in plugin.cfg.
and now

...
template:template
...
hosts:hostsconf
...

so maybe we need change the order about template and. hosts plugins.

@lixd lixd added the question label Apr 27, 2022
@chrisohaver
Copy link
Member

chrisohaver commented Apr 27, 2022

Yes, you can change the order of the items in plugin.cfg if you want your host plugin answers to take precedence over the template plugin answers. This requires re-building coredns and using that custom image/binary.

Another less optimal* way to solve it but doesn't require a re-build is to use self forwarding to a second server block listening on a separate port:

b.com:53 {
    hosts {
        1.2.3.4 r1.b.com
        2.3.4.5 r1.b.com
        fallthrough
    }
   forward . localhost:5300
}

b.com:5300 {
    template IN A b.com {
        match .*\.b\.com
        answer "{{ .Name }} 60 IN A 11.22.33.44"
        answer "{{ .Name }} 60 IN A 22.33.44.55"
        fallthrough
    }
   forward . /etc/resolv.conf
}

* less optimal because it introduces an extra hop.

@chrisohaver chrisohaver added the answered The question has been answered label Apr 27, 2022
@lixd
Copy link
Author

lixd commented Apr 28, 2022

@chrisohaver thanks for your immediate and detailed reply, it works for me.
Bytheway is this plugin's order need to change in this repo ?, maybe generic resolve record higher than accurate resolve record violates DNS rules.

@chrisohaver
Copy link
Member

chrisohaver commented Apr 28, 2022

Bytheway is this plugin's order need to change in this repo ?, maybe generic resolve record higher than accurate resolve record violates DNS rules.

We should not change it in this repo. If we were to do so, it would be a backward incompatible change for those who rely on the current order. The current behavior does not violate DNS rules.

A very different way to solve your example without a re-build is using the file plugin with it's zonefile containing wildcard A records for *.b.com, and normal A records for r1.b.com. This would not require the self-forwarding trick (or the hosts plugin). This is a cleaner solution than using hosts in conjunction with template.

@lixd lixd closed this as completed Apr 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered The question has been answered question
Projects
None yet
Development

No branches or pull requests

2 participants