这是我的 /etc/nftables.conf
#!/usr/sbin/nft -f
flush ruleset
define wan = { eth0 }
table inet filter {
chain input {
type filter hook input priority 0; policy drop;
# allow everything from loopback interface
iif lo accept comment "Accept any localhost traffic"
# drop invalid connection attempts
ct state invalid drop comment "Drop all invalid connection attempts"
# allow established and related connections
ct state established,related accept comment "Accept all traffic initiated by us"
# allow explicitly allowed services/ports/protocols
iif $wan tcp dport 22 accept comment "wan"
# Apply extra (manual configured) rules
# reject everything that has not been accepted before
reject with icmpx type admin-prohibited comment "Drop everything, which is not explicitly allowed"
}
chain forward {
type filter hook forward priority 0; policy drop;
# allow everything from loopback interface
iif lo accept comment "Accept any localhost traffic"
# drop invalid connection attempts
ct state invalid drop comment "Drop all invalid connection attempts"
# Apply extra (manual configured) rules
# reject everything that has not been accepted before
reject with icmpx type admin-prohibited comment "Drop everything, which is not explicitly allowed"
}
chain output {
type filter hook output priority 0; policy accept;
# Apply extra (manual configured) rules
}
}
journalctl -u nftables.service
这是我运行后得到的结果systemctl restart nftables.service
:
Feb 01 18:54:40 mydomain.net systemd[1]: Starting nftables...
Feb 01 18:54:40 mydomain.net nft[1682]: /etc/nftables.conf:14:13-33: Error: Could not process rule: No such file or directory
Feb 01 18:54:40 mydomain.net nft[1682]: ct state invalid drop comment "Drop all invalid connection attempts"
Feb 01 18:54:40 mydomain.net nft[1682]: ^^^^^^^^^^^^^^^^^^^^^
Feb 01 18:54:40 mydomain.net nft[1682]: /etc/nftables.conf:16:13-47: Error: Could not process rule: No such file or directory
Feb 01 18:54:40 mydomain.net nft[1682]: ct state established,related accept comment "Accept all traffic initiated by us"
Feb 01 18:54:40 mydomain.net nft[1682]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Feb 01 18:54:40 mydomain.net nft[1682]: /etc/nftables.conf:21:13-51: Error: Could not process rule: No such file or directory
Feb 01 18:54:40 mydomain.net nft[1682]: reject with icmpx type admin-prohibited comment "Drop everything, which is not explicitly allowed"
Feb 01 18:54:40 mydomain.net nft[1682]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Feb 01 18:54:40 mydomain.net nft[1682]: /etc/nftables.conf:29:13-33: Error: Could not process rule: No such file or directory
Feb 01 18:54:40 mydomain.net nft[1682]: ct state invalid drop comment "Drop all invalid connection attempts"
Feb 01 18:54:40 mydomain.net nft[1682]: ^^^^^^^^^^^^^^^^^^^^^
Feb 01 18:54:40 mydomain.net nft[1682]: /etc/nftables.conf:32:13-51: Error: Could not process rule: No such file or directory
Feb 01 18:54:40 mydomain.net nft[1682]: reject with icmpx type admin-prohibited comment "Drop everything, which is not explicitly allowed"
Feb 01 18:54:40 mydomain.net nft[1682]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Feb 01 18:54:40 mydomain.net systemd[1]: nftables.service: Main process exited, code=exited, status=1/FAILURE
Feb 01 18:54:40 mydomain.net systemd[1]: nftables.service: Failed with result 'exit-code'.
Feb 01 18:54:40 mydomain.net systemd[1]: Failed to start nftables.
当我注释以“ct state”开头的规则时,服务启动时没有错误。这里出了什么问题?同样的规则集在其他机器上运行良好。
系统信息:
操作系统:Debian 10
内核:4.19.0-14-amd64
答案1
对于遇到此问题的其他人。确保:
- “netfilter”(和相应的)内核选项直接编译或作为模块编译(grep -i netfilter /proc/config* 或 grep -i netfilter /boot/config*)
- 如果该选项已编译为模块,请确保没有将 sysctl 选项 kernel.modules_disabled 设置为 1。(编辑 /etc/sysctl.conf)