CoreDNS plugin for hosts-like hostnames with regular expressions support

Gato 45101f1788 rehosts coredns plugin 1 month ago
LICENSE 45101f1788 rehosts coredns plugin 1 month ago
NOTICE 45101f1788 rehosts coredns plugin 1 month ago
README.md 45101f1788 rehosts coredns plugin 1 month ago
rehosts.go 45101f1788 rehosts coredns plugin 1 month ago
rehosts_test.go 45101f1788 rehosts coredns plugin 1 month ago
rehostsfile.go 45101f1788 rehosts coredns plugin 1 month ago
rehostsfile_test.go 45101f1788 rehosts coredns plugin 1 month ago
setup.go 45101f1788 rehosts coredns plugin 1 month ago

README.md

Rehosts

CoreDNS hosts-like records plugin with support of regular expressions matching. Based on hosts plugin functionality and extended with regexp.

Install

Add this plugin to (plugin.cfg in coredns source)[https://github.com/coredns/coredns/blob/master/plugin.cfg]:


...
minimal:minimal
template:template
transfer:transfer

# Somewhere here to have regex priority voer stock hosts
rehosts:github.com/bitrate16/rehosts

rehosts:rehosts
hosts:hosts
route53:route53
...

Run to build coredns


make

And enjoy sample config:


.:53 {
    reload 2s

    rehosts ./rehosts {
        ttl 3600
        reload 60s
        fallthrough
    }

    forward . 1.1.1.1

    log
    errors
    debug
}

File syntax

File syntax is similar to /etc/hosts with additons:


# This is your hosts:
127.0.0.1 google.com


# This is your hosts on drugs:

# Regular, fully backwards-compatible with hosts
127.0.0.1 google.com
127.0.0.1 google.uk google.eu

# Wildcard or something. idk, I use cash
127.0.0.2 *.google.com
127.0.0.2 *.bing.com *.bing.cn
127.0.0.2 *.yeet.*

# regex, silly
127.0.0.3 @ ([a-n]+\.)?g?oogle\.(com|eu)

# unicode too
127.0.0.4 бебро.ед


Behavior

Rules are evaluated sequently and in a strict order. This means if non-regex domain is placed above regex, it has priority over regex:


# In this example
127.0.0.1 foo.bar.baz
1.0.0.127   *.bar.baz

# Request for "NAME=foo.bar.baz" will return "127.0.0.1"

NOTE: Because if sequential evaulation, large amount of rules may cause performance drop.

Blocklist example

127.0.0.1 analytics.google.com *.analytics.google.com
127.0.0.1 analytics.yandex.ru *.analytics.yandex.ru
127.0.0.1 *analytics.meta.com

127.0.0.1 @ .*telemetry.*
127.0.0.1 @ .*analytics.*
127.0.0.1 @ .*metrics.*
127.0.0.1 @ .*heartbeat.*

# e.t.c...