COREDNS-HOSTS(7)
π COREDNS-HOSTS(7) β the hosts plugin, explained by your fave sysadmin bestie β¨
okay so real talk, this is a page from the CoreDNS Plugins manual, and it's all about the hosts plugin. buckle up, it's actually so good π«Ά
πΈ NAME πΈ
hosts β enables serving zone data from a /etc/hosts style file. literally that's it, that's the vibe π
β¨ DESCRIPTION β¨
okay so the hosts plugin is lowkey iconic for serving zones straight out of a /etc/hosts file. it serves from a preloaded file that exists on disk β and the way it's always checking that file for changes and updating the zones accordingly?? main character energy fr fr π
important: this plugin only supports A, AAAA, and PTR records. that's the whole roster, no notes π
and bestie, you can absolutely use it with the readily available hosts files that block access to advertising servers β you know the ones π¦
it reloads the content of the hosts file every 5 seconds. upon reload, CoreDNS will use the new definitions. and if the file gets deleted?? any inlined content will continue to be served (she's resilient like that π). when the file is restored, it will then again be used. slay.
if you want to pass the request to the rest of the plugin chain whenever there's no match in the hosts plugin, you must specify the fallthrough option. no fallthrough, no passing, periodt.
π one tiny caveat bestie: this plugin can only be used once per Server Block. that's the rule, i don't make them.
π¦ THE HOSTS FILE π¦
commonly the entries are of the form IP_address canonical_hostname [aliases...] β as explained by the hosts(5) man page. iykyk.
examples:
127.0.0.1 localhost
192.168.1.10 example.com example
::1 localhost ip6-localhost ip6-loopback
fdfc:a744:27b5:3b0e::1 example.com example
β WILDCARD RECORDS β
owner names may use a * as the leftmost label to match one additional label below that name. this follows the same wildcard semantics as the file plugin. no cap.
examples:
192.168.1.10 *.example.com
192.168.1.11 a.example.com
192.168.1.12 b.example.com
with the entries above:
a.example.comandb.example.comresolve to their explicit addresses.apps.example.comresolves to192.168.1.10.example.comdoes not match the wildcard (the zone apex is excluded π«).deep.apps.example.comdoes not match*.example.com(only one label is matched β she's not greedy like that).
π also: wildcard entries do not generate PTR records. noted.
π PTR RECORDS π
PTR records for reverse lookups are generated automatically by CoreDNS (based on the hosts file entries) and cannot be created manually. so don't even try, bestie π
π SYNTAX π
hosts [FILE [ZONES...]] {
[INLINE]
ttl SECONDS
no_reverse
reload DURATION
fallthrough [ZONES...]
fallthrough_unsupported
}
FILEβ the hosts file to read and parse. if the path is relative, the path from therootplugin will be prepended to it. defaults to/etc/hostsif omitted. we scan the file for changes every 5 seconds. πZONESβ zones it should be authoritative for. if empty, the zones from the configuration block are used.INLINEβ the hosts file contents inlined in Corefile. if there are any lines beforefallthroughthen all of them will be treated as the additional content for hosts file. the specified hosts file path will still be read but entries will be overridden. wild but true.ttlβ change the DNS TTL of the records generated (forward and reverse). the default is3600seconds (1 hour). β°reloadβ change the period between each hostsfile reload. a time of zero seconds disables the feature. examples of valid durations:"300ms","1.5h"or"2h45m". see Go's time package athttps://godoc.org/time. π§no_reverseβ disable the automatic generation of thein-addr.arpaorip6.arpaentries for the hosts.fallthroughβ if zone matches and no record can be generated, pass request to the next plugin. if[ZONES...]is omitted, then fallthrough happens for all zones for which the plugin is authoritative. if specific zones are listed (for examplein-addr.arpaandip6.arpa), then only queries for those zones will be subject to fallthrough. by default, queries for unsupported record types return an authoritative NODATA response when the queried name has anAorAAAAentry in the hosts data.fallthrough_unsupportedβ extends fallthrough to unsupported query types when the queried name exists in the hosts data. for example,TXT,HTTPS, andSVCBqueries for a name with anAorAAAAentry are passed to the next plugin. if that plugin isforward, these queries are sent upstream. π this option requiresfallthroughand uses the same zone scope.
π₯ METRICS π₯
if monitoring is enabled (via the prometheus plugin) then the following metrics are exported:
coredns_hosts_entries{}β the combined number of entries in hosts and Corefile.coredns_hosts_reload_timestamp_seconds{}β the timestamp of the last reload of hosts file. β±οΈ
π EXAMPLES π
load /etc/hosts file.
. {
hosts
}
load example.hosts file in the current directory.
. {
hosts example.hosts
}
load example.hosts file and only serve example.org and example.net from it, and fall through to the next plugin if the query doesn't match.
. {
hosts example.hosts example.org example.net {
fallthrough
}
}
load hosts file inlined in Corefile.
example.hosts example.org {
hosts {
10.0.0.1 example.org
fallthrough
}
whoami
}
resolve all single-label subdomains of example.com to one address, with explicit exceptions, and fall through for everything else under example.com. this one ate, honestly π
. {
hosts example.hosts example.com {
192.168.1.10 *.example.com
192.168.1.11 www.example.com
fallthrough example.com
}
forward . 8.8.8.8
}
π SEE ALSO π
the form of the entries in the /etc/hosts file are based on IETF RFC 952 at https://www.rfc-editor.org/info/rfc952/ which was updated by IETF RFC 1123 at https://www.rfc-editor.org/info/rfc1123/. go read them, they're giving original lore π
and that's the whole page bestie!! this little writeup is from the CoreDNS manual, dated October 2026 β mwah, go configure something cute π β¨π«Ά
π¦ where this page comes from
- opensuse-leap 16.0: coredns-extras 1.15.0-bp160.1.1 Β· Apache-2.0 AND MPL-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms