我在 openSUSE Tumbleweed 上将 nftables 设置为默认防火墙,也是唯一的防火墙。iptables 和 Firewalld 已被标记为“禁忌”,永远不会重新安装。我还检查了两次,确保它们不在我的系统中。只有 nftables,其他都一样。
我的问题是过滤器内的输出/输入链inet
似乎不会影响 NAT 设备。nftables 也充当我的家庭网络的 NAT。
我有大约 8 台设备始终处于连接状态,因此进行了 NAT 处理。这些设备(全部)都无法通过我的output
和input
链,因为 和 链的限制非常严格。
我没有,也无法找到任何有关如何确保 NAT 设备通过其他表和链运行的信息。
有人能解释一下为什么 nftables 不通过其他表和链路由 NAT 流量吗?有人能提供一种方法,让 NAT 数据通过其他防火墙表发送吗?
这是我的 nftables.conf 文件:
#!/usr/sbin/nft -f
flush ruleset
table inet filter{
chain state{
ct state {established, related} accept;
ct state invalid drop;
}
chain input{
type filter hook input priority 0; policy drop;
# allowed icmp types
ip protocol icmp icmp type {destination-unreachable, router-solicitation, router-advertisement, time-exceeded, parameter-problem} accept;
# if related or invalid
jump state;
# allow loopback
iif "lo" accept;
# NTP (Network Time)
udp dport 123 accept;
tcp dport 123 accept;
}
chain output{
type filter hook output priority 0; policy drop;
# allowed icmp types
ip protocol icmp icmp type {destination-unreachable, router-solicitation, router-advertisement, time-exceeded, parameter-problem} accept;
# if related or invalid
jump state;
# allow loopback
iif "lo" accept;
# allow TCP ident
tcp dport 113 accept;
# allow dns & dnssec
tcp dport { 53, 853 } accept;
udp dport { 53, 853 } accept;
# allow http
tcp dport { 80, 443, 1443, 8443, 8080 } accept;
udp dport { 80, 443, 1443, 8443, 8080 } accept;
# allow ftp
tcp dport { 20, 21 } accept;
udp dport 69 accept;
# allow ssh
tcp dport 22 accept;
udp dport 22 accept;
# allow email
tcp dport { 25, 465, 587 } accept; #SMTP & SMTPS
tcp dport { 110, 995 } accept; #POP3 & POP3S
udp dport { 110, 995 } accept; #POP3 & POP3S
tcp dport { 143, 993 } accept; #IMAP & IMAPS
udp dport { 143, 993 } accept; #IMAP & IMAPS
tcp dport 691; #MS Exchange
# IPsec VPN
udp dport { 500, 4500, 1701 } accept;
esp spi 50 accept;
ah spi 51 accept;
# NTP (Network Time)
udp dport 123 accept;
tcp dport 123 accept;
}
chain IPS_input{
type filter hook input priority 10; policy drop;
queue num 0
}
chain IPS_output{
type filter hook output priority 10; policy drop;
queue num 0;
}
chain IPS_forward {
type filter hook forward priority 10; policy drop;
queue num 0;
}
}
table nat {
chain prerouting {
type nat hook prerouting priority -100;
ct state invalid drop;
}
chain postrouting {
type nat hook postrouting priority 100;
ct state invalid drop;
ip saddr 10.0.0.0/24 oif eno2 masquerade; # "eno2" is our external interface
}
}
虽然它是否经过 NAT 并不完全相关,但无论如何,它都意味着转发的流量就是所关注的流量(即,来自某个其他主机的流量最终(即,在
dnat
et al. 之后,如果有的话)目的地是另一个主机,因此被路由到另一个主机)。对于此类流量,您需要一个带有 的链来过滤。带有/
hook forward
的链仅允许 (L3-) 发往此主机 / 源自此主机的流量通过。(另请注意,这些流量不会通过带有或 的链。)hook input
hook output
hook forward