nftables


###################################################################

1 表

1.1 增加表

  • 格式:
 nft add table <family名> <表名> 
  • 例子:
 nft add table bridge filter

1.2 删除表

  • 格式:
nft delete table <family名> <表名> 
  • 例子:
nft delete table bridge filter

2 链

2.1 增加链

  • 格式:
nft add chain <family名> <表名> <链名>

3 规则

3.1 增加规则

  • 格式:
 nft add rule <family名> <表名> <链名> <规则>
  • 例子:
 nft add rule inet fw4 forward tcp dport 80 counter

3.2 插入规则

先list出来规则需要插入的位置,然后在位置前面插入规则

  • 格式:
nft -a list chain  <family名> <表名> <链名>
nft insert rule <family名> <表名> <链名> position <handle索引> <规则>
  • 举例
    在这里插入图片描述

3.3 删除规则

先list出来规则所在的位置,然后删除

  • 格式:
nft -a list chain  <family名> <表名> <链名>
nft delete rule <family名> <表名> <链名> handle <handle索引>
  • 举例:
    在这里插入图片描述

4 调试

4.1 增加log规则

4.1.1 转发链中TCP目的端口为5201的报文

在这里插入图片描述

4.2 增加统计规则

4.2.1 统计netdev的ping包

nft add table netdev filter
nft add chain netdev filter input { type filter hook ingress device lan3 priority 0 \; }
nft insert rule netdev filter input ip protocol icmp counter

4.2.2 统计桥的ping包

  • 桥 "prerouting"统计
nft add table bridge br_table
nft add chain bridge br_table prerouting { type filter hook prerouting priority 0 \; }
nft add rule bridge br_table prerouting ip protocol icmp counter
  • 桥"input"统计
nft add table bridge br_table
nft add chain bridge br_table input { type filter hook input priority 0 \; }
nft add rule bridge br_table input ip protocol icmp counter

5 修改报文内容

5.1 修改MAC地址

5.1.1 根据目的ip修改目的mac

#!/usr/sbin/nft -f
table bridge brfilter {
    chain prerouting {
        type filter hook prerouting priority 0; policy accept;
        ip daddr 192.168.18.1 ether daddr set xx:xx:xx:xx:xx:xx    
    }
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值