大网数据广告活动
服务器运维问答

nftables does not write to syslog

· 52CE 我爱测

Running Debian 10 on a LXC container: # apt-get -y install nftables # nft --version nftables v0.7 (Scrooge McDuck) # nft flush ruleset # nft add table inet filter # nft add chain inet filter input # nft add rule inet filter input…

问题原文

原帖链接 · Julen Larrucea · CC BY-SA 4.0

Running Debian 10 on a LXC container:

# apt-get -y install nftables
# nft --version
nftables v0.7 (Scrooge McDuck)
# nft flush ruleset
# nft add table inet filter
# nft add chain inet filter input
# nft add rule inet filter input log
# nft list ruleset
table inet filter { 
    chain input {
        log
    }
}

Then, I go to /var/log/syslog, create some network traffic and... I see no message from nftables at all.

I also tried (unsuccessfully) to define the rule this way:

nft add rule inet filter input log prefix \"FINDME \" counter

More tests:

# logger test && tail -1 /var/log/syslog
Aug 18 20:39:53 my-server root: test
# echo "test2" | systemd-cat && tail -1 /var/log/syslog
Aug 18 20:40:52 my-server cat[1907]: test2
# uname -v
 #1 SMP PVE 5.4.34-2 (Thu, 07 May 2020 10:02:02 +0200)

Why is nftables not writing to my syslog ?

As a bonus question: would there be any way to trigger an action when a match occurs? For example store blocked IPs on a database.

已采纳解答

原帖链接 · Julen Larrucea · CC BY-SA 4.0

Well... Thanks to the clue of @anx I figured out that apparently netfilter has some difficulties to send the data to rsyslog.

It probably has something to do with the fact that the host is a LXC container without own kernel and the cgroups in the hypervisor... (Buff, I'm getting into dark territory)... Well... Whatever.

Anyway, if somebody happens to have a similar issue, I managed to get some log by sending the data into ulogd. These are the steps to get a basic example working:

# apt-get -y install nftables ulogd2
# nft flush ruleset
# nft add table inet filter
# nft add chain inet filter input '{ type filter hook input priority 0 ; }'
# nft add rule inet filter input log prefix "FINDME" group 0 accept
# nft list ruleset
table inet filter {
    chain input {
        type filter hook input priority 0; policy accept;
        log prefix "FINDME" group 0 accept
    }
}
# tail -f /var/log/ulog/syslogemu.log

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-08-18)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。