dbhost

package
v0.5.26 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2025 License: BSD-3-Clause Imports: 16 Imported by: 0

README

Name

dbhosts - serve data from /etc/hosts

Description

The dbhost handler is useful for serving data from a /etc/hosts file. It watches the file and reloads it when written to. The dbhost handler can only reply to A, AAAA and PTR queries, all others are deferred to the next handler(s).

The dbhost handler can be used with readily available hosts files that block access to advertising servers.

The hosts file

Commonly the entries are of the form IP_address canonical_hostname [aliases...] as explained by the hosts(5) man page.

Examples:

# The following lines are desirable for IPv4 capable hosts
127.0.0.1       localhost
192.168.1.10    example.com            example

# The following lines are desirable for IPv6 capable hosts
::1                     localhost ip6-localhost ip6-loopback
fdfc:a744:27b5:3b0e::1  example.com example

Reverse lookups

PTR records for reverse lookups are generated automatically.

Syntax

dbhost [FILE] {
    ttl TTL
}
  • FILE the hosts file to read and parse. If the path is relative the path from the root handler will be prepended to it. Defaults to/etc/hosts if omitted.
  • ttl change the TTL of the records generated (forward and reverse). The default is 3600 seconds (1 hour).

Examples

Load /etc/hosts file.

. {
    dbhost
}

Load example.hosts file in the current directory (if root is not set), and only use it for example.org names:

example.org {
    dbhost example.hosts
}

See also

The form of the entries in the /etc/hosts file are based on IETF RFC 952 which was updated by IETF RFC 1123.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Err added in v0.5.2

func Err(err error) slog.Attr

Types

type Dbhost

type Dbhost struct {
	Path string

	Data         map[string]dnszone.Node
	sync.RWMutex // protects Data
	// contains filtered or unexported fields
}

func (*Dbhost) Err

func (h *Dbhost) Err(err error) error

func (*Dbhost) HandlerFunc

func (d *Dbhost) HandlerFunc(next dns.HandlerFunc) dns.HandlerFunc

func (*Dbhost) Key

func (h *Dbhost) Key() string

func (*Dbhost) Load

func (d *Dbhost) Load() error

func (*Dbhost) Reload

func (d *Dbhost) Reload() error

Reload launches a reload routine that listens for _write_ events to the hosts file.

func (*Dbhost) Setup

func (d *Dbhost) Setup(co *dnsserver.Controller) error

Jump to

Keyboard shortcuts

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