The hosts plugin provides local name-to-IP mappings similar to /etc/hosts. It’s useful for local overrides, test environments, split-horizon behavior, or to block/redirect specific domains.
A and AAAA queries. Other query types are ignored.Context.Lines follow a flexible format similar to common hosts files:
<ip> <hostname1> [hostname2] ... (IP first)# are commentsExamples:
# IPv4 and IPv6 for localhost
127.0.0.1 localhost
::1 localhost ip6-localhost
# Multiple names on one line
93.184.216.34 example.com www.example.com
# Hostname-first example (supported)
example.org 203.0.113.5
The parser accepts both IP-first and hostname-first formats on the same line and will associate every hostname token with all parsed IPs on that line.
The plugin supports the following configuration keys:
files — (string or sequence) paths to one or more hosts files to loadauto_reload — (bool) enable automatic reload when any watched file changesExample YAML configuration for the plugin:
plugins:
- tag: hosts
type: hosts
args:
files:
- examples/etc/hosts.txt
auto_reload: true
Notes:
auto_reload is enabled, the plugin watches the configured files and reloads after small debounce delay.-v / -vv) to see plugin initialization logs.Hosts loaded (wrapper) — indicates hosts were successfully loaded and reports number of entries and files.Failed to read hosts file — read error for a configured file (file missing or permission issue).Failed to parse hosts file during auto-reload — parsing error (invalid IP/token) when reloading.hosts runs before any plugin that would short-circuit or override its responsehosts early in the pipeline (default priority=100) to ensure local overrides are applied before expensive upstream queries.auto_reload: true during development for fast iteration, and consider disabling it for production deployments if filesystem stability is a concern.