尝试 NFT 防火墙

替换掉了 iptables。

配置文件 /etc/nftables.conf

#!/usr/sbin/nft -f

flush ruleset

table inet filter {
	chain input {
		type filter hook input priority 0;
                # 允许已建立的连接
                ct state established,related accept
                # 允许回环接口(本地访问)
                iif lo accept
                # 允许 SSH 连接(如果需要)
                tcp dport 22 accept

                # 允许 DNS 查询(来自特定 IP)
                ip saddr 209.123.1.15 tcp dport {53, 80, 443} accept
                ip saddr 209.123.1.15 udp dport {53, 80, 443} accept
                ip saddr 38.100.10.10 tcp dport {53, 80, 443} accept
                ip saddr 38.100.10.10 udp dport {53, 80, 443} accept

						    # 默认禁止:
                tcp dport {53, 80, 443} drop
                udp dport {53, 80, 443} drop

	}
	chain forward {
		type filter hook forward priority 0;
	}
	chain output {
		type filter hook output priority 0;
	}
}

重载配置: nft -f /etc/nftables.conf