服务管理
查看 CoreDNS 状态:
systemctl status coredns
重启 CoreDNS:
systemctl restart coredns
重新加载 CoreDNS:
systemctl reload coredns
停止 CoreDNS:
systemctl stop coredns
启动 CoreDNS:
systemctl start coredns
查看 CoreDNS 日志:
journalctl -u coredns -f
DNS 配置
CoreDNS 的主配置为:
/etc/coredns/Corefile
默认配置将 DNS 查询转发至:
1.1.1.1 8.8.8.8
请根据你的具体需求和使用场景配置 Corefile。
修改 Corefile 后重启 CoreDNS:
systemctl restart coredns
DNS 端点
- DNS:
53/tcp和53/udp - 健康检查:
http://127.0.0.1:8080/health - 就绪检查:
http://127.0.0.1:8181/ready - 指标:
http://127.0.0.1:9153/metrics
重要文件与目录
- 二进制文件:
/usr/bin/coredns - Corefile:
/etc/coredns/Corefile - 服务:
/etc/systemd/system/coredns.service - Sysusers:
/usr/lib/sysusers.d/coredns.conf - Tmpfiles:
/usr/lib/tmpfiles.d/coredns.conf - Logrotate:
/etc/logrotate.d/coredns - 数据目录:
/var/lib/coredns - 日志文件:
/var/log/coredns.log - 错误日志:
/var/log/coredns.err.log - 解析器覆盖设置:
/etc/systemd/resolved.conf.d/99-coredns.conf
测试 DNS 解析
直接查询 CoreDNS:
dig @127.0.0.1 example.com
或使用服务器 IP 进行查询:
dig @<SERVER-IP> example.com
The host's /etc/resolv.conf is configured to use:
nameserver 127.0.0.1
注意事项
- CoreDNS uses
systemd-resolved配置更改以释放 53 端口。 - The host resolver is pointed to
127.0.0.1. - DNS 查询会转发到已配置的上游解析器。
- CoreDNS runs under the dedicated
corednssystem user.