#! /bin/bash
#清空当前规则集:
nft flush ruleset
#查询当前规则集:
nft list ruleset
#添加一个表:
nft add table inet filter
#添加input、forward和output三个基本链。input和forward的默认策略是drop。output的默认策略是accept。
nft add chain inet filter input { type filter hook input priority 0 \; policy drop \; }
nft add chain inet filter forward { type filter hook forward priority 0 \; policy drop \; }
nft add chain inet filter output { type filter hook output priority 0 \; policy accept \; }
#添加两个与TCP和UDP关联的常规链:
nft add chain inet filter TCP
nft add chain inet filter UDP
#related和established的流量会accept:
nft add rule inet filter input ct state related,established accept
#loopback接口的流量会accept:
nft add rule inet filter input iif lo accept
#无效的流量会drop:
nft add rule inet filter input ct state invalid drop
#新的echo请求(ping)会accept:
nft add rule inet filter input ip protocol icmp icmp type echo-request ct state new accept
#新的UDP流量跳转到UDP链&#x
nftables脚本例子:过滤和NAT
最新推荐文章于 2024-08-09 15:41:38 发布