nft
让我头疼不已,无论我如何调整政策,我仍然无法让它发挥作用。
我想到的概念:
- 一个存在通用规则的“基础”链(例如允许
ssh
等) - 一个或多个特定于守护程序特定规则所在的应用程序(例如 http 服务器链)
我尝试了许多不同的规则排列,但我永远无法同时获得“基础”+ 守护程序流量,我总是最终阻止其中一个!;-(
这是我当前的(简化的)配置(目前构成它允许ssh
但不允许http
)
/etc/nftables.conf:
#!/usr/sbin/nft -f
flush ruleset
table inet filter {
counter input_ssh {}
set my_admin_ipv4 {
type ipv4_addr
flags interval
counter
elements = {
10.0.0.0/8,
172.16.0.0/12,
192.168.0.0/16
}
}
chain input {
type filter hook input priority filter;
iifname lo accept comment "Allow loopback traffic";
ct state established,related accept comment "Allow established/related connections";
ct state invalid drop comment "Deny invalid connections";
# SSH
tcp dport ssh ip saddr @my_admin_ipv4 counter name input_ssh accept comment "Allow IPv4 SSH from Admin";
policy drop;
}
chain forward {
type filter hook forward priority 0;
policy drop;
}
chain output {
type filter hook output priority 0;
}
include "/etc/nft/*.conf"
}
/etc/nft/http.conf:
counter input_http {}
chain http {
type filter hook input priority filter - 1;
# HTTP #
tcp dport {80,443} counter name input_nginx accept comment "Allow HTTP";
policy accept;
}