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

add middleware/hosts (for reading entries from /etc/hosts file) #678

Closed
zoonderkins opened this issue May 29, 2017 · 10 comments
Closed

add middleware/hosts (for reading entries from /etc/hosts file) #678

zoonderkins opened this issue May 29, 2017 · 10 comments
Labels

Comments

@zoonderkins
Copy link

zoonderkins commented May 29, 2017

My settings like this

proxy . 127.0.0.1:5454 {
policy round_robin
fail_timeout 3s
*** lookup custom hosts file (ads block like, 0.0.0.0 ssl.google.com)
spray
protocol https_google
}
cache 160
log stdout
errors stdout

@miekg
Copy link
Member

miekg commented May 29, 2017 via email

@zoonderkins
Copy link
Author

Yap, sorry for my english
I have a list of hosts file with 0.0.0.0 xxx.com
I want it to lookup from hosts first, if match then return 0.0.0.0, else lookup from upstream dns like 8.8.8.8

@zoonderkins
Copy link
Author

zoonderkins commented May 29, 2017

my solution from now I just use dnsmasq(my hosts file) then forward upstream to coredns

@miekg
Copy link
Member

miekg commented May 29, 2017 via email

@miekg miekg changed the title How can I read my custom hosts file add middleware/hosts (for reading entries from /etc/hosts file) May 30, 2017
@miekg
Copy link
Member

miekg commented May 30, 2017

Add a new middleware like this is also a good way to get started with coding in CoreDNS

@miekg
Copy link
Member

miekg commented May 30, 2017

Specifically the middleware should:

  • parse and reparse /etc/hosts every x seconds or on change
  • probably needs fallthrough support, just like we did in the kubernetes middleware
  • hook up the middleware into CoreDNS

@miekg miekg added the plugin label May 30, 2017
@zoonderkins
Copy link
Author

@pmoroney
Copy link
Collaborator

I worked on this a bit last night.
I pulled a lot of inspiration from the auto backend and copied the host file logic from hosts.go in the net package.
I got it to compile and run, but it seems I have the logic wrong for when to return errors and when to use middleware.NextOrFailure.
I'll read up more about it tonight.

Thank's for suggesting this on twitter, I wanted to get involved and this is a good starting point.

@miekg
Copy link
Member

miekg commented May 31, 2017

Feel free to put a gist online (or on actual PR) so we can easily discuss the code.

Awesome getting you onboard!

@miekg
Copy link
Member

miekg commented Jun 9, 2017

We have the hosts middleware now

@miekg miekg closed this as completed Jun 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants