我最近开始使用unbound dns。
我已经正确配置了我需要的所有东西。但是当我进行查询时服务器不会记录。
我的 unbound.conf 文件中没有错误
以下是我的 .conf 文件
# The server clause sets the main parameters.
server:
# whitespace is not necessary, but looks cleaner.
# verbosity number, 0 is least verbose. 1 is default.
verbosity: 1
# print statistics to the log (for every thread) every N seconds.
# Set to "" or 0 to disable. Default is disabled.
statistics-interval: 5
interface: 192.168.116.134
# port to answer queries from
port: 53
cache-min-ttl: 400
cache-max-ttl: 86400
# Enable IPv4, "yes" or "no".
do-ip4: yes
# Enable IPv6, "yes" or "no".
# do-ip6: yes
# Enable UDP, "yes" or "no".
do-udp: yes
# Enable TCP, "yes" or "no".
do-tcp: yes
access-control: 0.0.0.0/0 allow
# chroot: "/etc/unbound"
# username: "unbound"
# directory: "/etc/unbound"
# the log file, "" means log to stderr.
# Use of this option sets use-syslog to "no".
logfile: "/var/log/unbound/unbound.log"
forward-zone:
name: "."
forward-addr: 8.8.4.4
forward-addr: 8.8.8.8
Run Code Online (Sandbox Code Playgroud)
lig 文件确实存在于给定目录中,并且我已使用 使未绑定用户成为其所有者chown,但是当我进行查询时,日志文件仍然为空。
平台:Ubuntu 18 桌面版
默认情况下,Unbound Debian/Ubuntu/类似软件包会记录到/var/log/syslog。经过一番尝试和错误后,我弄清楚了如何改变它。
步骤1
确保所有 CHROOT 指令都被注释掉并添加了 log 指令:
搜索指令:
sudo grep -R "chroot" /etc/unbound/*
Run Code Online (Sandbox Code Playgroud)
注意:我们正在搜索整个配置区域。您的配置文件位置可能会有所不同。我把我的放在下面/etc/unbound/unbound.conf.d/99-custom-(servername).conf。
无论如何,如果注释正确的话,您应该会看到类似这样的内容:
# chroot:""
Run Code Online (Sandbox Code Playgroud)
另请确保您的配置文件中包含以下条目:
use-syslog: no
logfile: "/var/log/unbound/unbound.log"
Run Code Online (Sandbox Code Playgroud)
注意:您可以将日志保存在任何您喜欢的位置,但如果您遵循本指南的其余部分,则必须调整路径/文件名。
第2步
确保使用正确的所有者(未绑定)和权限创建文件夹/文件:
sudo mkdir /var/log/unbound && sudo chmod 755 /var/log/unbound
sudo touch /var/log/unbound/unbound.log
sudo chown unbound:unbound /var/log/unbound /var/log/unbound/unbound.log
Run Code Online (Sandbox Code Playgroud)
重新启动服务后,它仍然对我(或你)不起作用。
我注意到在调高详细程度进行调试后它仍在记录到系统日志。我还注意到一些内核日志记录显示“apparmor”正在记录“DENIED”以进行未绑定的日志位置访问:
sudo cat /var/log/syslog | grep DENIED
Run Code Online (Sandbox Code Playgroud)
系统日志中的示例:
Dec 30 16:41:48 ip-192-168-1-1 kernel: [ 1368.641789] audit: type=1400 audit(1577724108.624:29): apparmor="DENIED" operation="open" profile="/usr/sbin/unbound" name="/var/log/unbound/unbound.log" pid=2247 comm="unbound" requested_mask="ac" denied_mask="ac" fsuid=112 ouid=112
Run Code Online (Sandbox Code Playgroud)
步骤3
为了纠正这个问题,我向区域添加了本地apparmor.d覆盖:
sudo nano /etc/apparmor.d/local/usr.sbin.unbound
Run Code Online (Sandbox Code Playgroud)
添加这一行:
/var/log/unbound/unbound.log rw,
Run Code Online (Sandbox Code Playgroud)
(是的,末尾有一个逗号。)保存。
步骤4
重新加载未绑定的 apparmor 条目:
sudo apparmor_parser -r /etc/apparmor.d/usr.sbin.unbound
Run Code Online (Sandbox Code Playgroud)
步骤5
重新启动未绑定:
sudo systemctl restart unbound
Run Code Online (Sandbox Code Playgroud)
检查日志:
$ sudo tail -f /var/log/unbound/unbound.log
[1577725445] unbound[2721:0] info: start of service (unbound 1.6.7).
Run Code Online (Sandbox Code Playgroud)
作品。如果您注意到,当系统日志记录它时,它使用标准日期格式。但是,Unbound 自定义日志记录/非系统日志默认使用Unix/Epoch 时间(自 1970 年以来的秒数)。如果您希望拥有像 syslog 这样的时间戳,请将其添加到未绑定的配置中并重新加载服务:
log-time-ascii: yes
Run Code Online (Sandbox Code Playgroud)
步骤6
日志轮换:
如果您希望使用logrotate服务轮换 Unbound 日志(您应该这样做),请将此位添加到文件中/etc/logrotate.d/unbound:
/var/log/unbound/*.log {
weekly
rotate 7
missingok
notifempty
compress
delaycompress
sharedscripts
create 644
postrotate
/usr/sbin/unbound-control log_reopen
endscript
}
Run Code Online (Sandbox Code Playgroud)
全部重新启动:
sudo systemctl restart logrotate.service unbound.service
密切关注日志记录一两周,以确保日志记录和旋转正确。
我的配置:
要点文本
参考文献:
https://nlnetlabs.nl/documentation/unbound/unbound.conf/
https://wiki.debian.org/AppArmor/Debug
https://gist.github.com/kometchtech/06fc3326c83338afd151
小智 0
您需要设置适当的详细级别。3应该足够了。
Run Code Online (Sandbox Code Playgroud)verbosity: <number> The verbosity number, level 0 means no verbosity, only errors. Level 1 gives operational information. Level 2 gives detailed operational information. Level 3 gives query level information, output per query. Level 4 gives algorithm level information. Level 5 logs client identification for cache misses. Default is level 1. The verbosity can also be increased from the command- line, see unbound(8).
小智 0
您正在 chroot 环境 ( /etc/unbound) 中运行,这意味着您的日志实际上应该保存在/etc/unbound/var/log/unbound/unbound.log. 这是您正在寻找的地方吗?
| 归档时间: |
|
| 查看次数: |
16154 次 |
| 最近记录: |