rehosts

package module
v0.0.0-...-45101f1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

README

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...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeFQDNnIDNA

func DeFQDNnIDNA(host string) (string, error)

Types

type Matcher

type Matcher interface {
	Match(*string) bool
}

type Rehosts

type Rehosts struct {
	Next plugin.Handler
	*RehostsFile

	Fall fall.F
}

func (Rehosts) Name

func (h Rehosts) Name() string

func (Rehosts) ServeDNS

func (rh Rehosts) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)

type RehostsFile

type RehostsFile struct {

	// List pf authoritative origins
	Origins []string

	// Update lock
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*RehostsFile) LookupStaticHostV4

func (r *RehostsFile) LookupStaticHostV4(host string) []net.IP

Lookup host IPv4 records

func (*RehostsFile) LookupStaticHostV6

func (r *RehostsFile) LookupStaticHostV6(host string) []net.IP

Lookup host IPv6 records

type RehostsFileRecord

type RehostsFileRecord struct {
	Match  func(str string) bool
	AddrV4 []net.IP
	AddrV6 []net.IP
}

Single hosts file record that maps regex matcher to IP (v4 or v6)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL