V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
OpenWrt 是一个专门面向嵌入式设备的 Linux 发行版。你可以将 OpenWrt 支持的型号的嵌入式设备,比如各种路由器上的系统,换成一个有更多可能性可以折腾的 Linux 系统。
OpenWrt 官方网站
qazwsxkevin
V2EX  ›  OpenWrt

23.05 在构建固件时,还能用回 iptables 么, nftables 感觉有些不太好用

  •  
  •   qazwsxkevin · 82 天前 · 1418 次点击
    这是一个创建于 82 天前的主题,其中的信息可能已经有所发展或是发生改变。

    在 menuconfig 里,似乎已经没有 iptables 能选了,openwrt 的 nftable 不知道是版本精简还是我自己语法问题..

    root@openwrt:~# nft add table trouter
    root@openwrt:~# 
    root@openwrt:~# 
    root@openwrt:~# 
    root@openwrt:~# nft add chain trouter icmp_filter { type filter hook input priority 0 \; }
    root@openwrt:~# nft add rule trouter icmp_filter iifname "eth0" icmp type echo-request drop
    root@openwrt:~# 
    root@openwrt:~# 
    root@openwrt:~# nft add rule trouter icmp_filter iifname "br-lan" icmp type echo-request drop
    root@openwrt:~# 
    root@openwrt:~# 
    root@openwrt:~# nft add rule trouter input iifname { "eth0", "br-lan" } icmp type echo-request counter jump icmp_filter
    Error: Could not process rule: No such file or directory
    add rule trouter input iifname { eth0, br-lan } icmp type echo-request counter jump icmp_filter
                     ^^^^^
    root@openwrt:~# 
    root@openwrt:~# nft add rule trouter input iifname eth0,br-lan icmp type echo-request counter jump icmp_filter
    Error: Basetype of type network interface name is not bitmask
    add rule trouter input iifname eth0,br-lan icmp type echo-request counter jump icmp_filter
                                   ^^^^
    root@openwrt:~# 
    root@openwrt:~# nft add rule trouter input iifname { eth0, br-lan } icmp type echo-request counter jump icmp_filter
    Error: Could not process rule: No such file or directory
    add rule trouter input iifname { eth0, br-lan } icmp type echo-request counter jump icmp_filter
                     ^^^^^
    root@openwrt:~# 
    root@openwrt:~# 
    

    要是 iptables ,这事情早结束了。。。。

    9 条回复    2024-07-27 22:52:53 +08:00
    qazwsxkevin
        1
    qazwsxkevin  
    OP
       82 天前
    这些语句都是看文档,问 chatgpt 拼装出来,debian 这样 linux 里能完整输入命令
    wuruxu
        2
    wuruxu  
       82 天前   ❤️ 1
    ```
    -----------------------------------------------------
    OpenWrt SNAPSHOT, r26907-62891c749d
    -----------------------------------------------------
    root@jdc128G:~# cat /etc/nftables.d/20-mangle-wgset.nft
    chain mangle_prerouting_wgset {
    type filter hook prerouting priority mangle; policy accept;
    ip daddr @wgset meta mark set 0x00003c25 counter accept
    ip6 daddr @wgset6 meta mark set 0x00003c26 counter accept
    }

    chain mangle_output_wgset {
    type route hook output priority mangle; policy accept;
    ip daddr @wgset meta mark set 0x00003c25 counter accept
    ip6 daddr @wgset6 meta mark set 0x00003c26 counter accept
    }
    ```
    可以把 nft 的 rule 添加到 /etc/nftables.d/ 这个目录下
    Earsum
        3
    Earsum  
       81 天前   ❤️ 1
    这个是 22.03 版的官方文档提供的方式,不知道 23 版是否仍然适用,而且这些工具集不是卸载 fw3 更换 fw4 ,而是提供兼容层?
    “iptables 工具集不再默认在固件中安装。若有需要,你可以通过 opkg 或者 ImageBuilder 来安装。iptables-nft, arptables-nft, ebtables-nft 和 xtables-nft 软件包可以在使用 nftables 的情况下,提供与之前的工具相同的命令接口。 ”
    by https://openwrt.org/zh/releases/22.03/notes-22.03.0
    junjiego2
        4
    junjiego2  
       80 天前   ❤️ 1
    最近从 lean 的 lede 换到 immortalwrt 23.05 ,从 iptables 换到 nftables 真的很不习惯,特别是没有了那个自定义规则
    szdosar
        5
    szdosar  
       80 天前   ❤️ 1
    我不确定的是不是用的官方的 openwrt 源码。

    如果是的话,你要在配置选单里,降级 firewall 版本:
    1.导航到 Base system --->
    2.取消 firewall4
    3.勾选 firewall

    如果你用的是 lede 源码,应该没有这个困扰。
    如果你用其他源码,没办法完成以上操作,你可能需要执行这条命令后才能进行以上修改:
    sed -i 's/+uci-firewall/+firewall/g' feeds/luci/applications/luci-app-firewall/Makefile
    ##文件 feeds/luci/applications/luci-app-firewall/Makefile 中所有的 +uci-firewall 都会被替换为 +firewall 。
    qazwsxkevin
        6
    qazwsxkevin  
    OP
       79 天前
    这个问题已解决,正如 3 楼给的 22.03 news 里面提到,在 23.05menuconfig 选上 iptables-nft, arptables-nft, ebtables-nft 和 xtables-nft ,构建好的固件,iptables 1.8 ,又回来了,与 nftables 也是共存的,事情解决,我不想用 nftables ,虽然这个是以后的趋势态度吧,以后再说了...

    @wuruxu #2 ,试过写了一些 nftables 的语句,没能正确起效,已经逃了
    @Earsum #3 ,感谢~
    @junjiego2 #4 ,已解决,23.05 也能用 iptables 了.
    @szdosar #5 ,thanks~
    sq123
        7
    sq123  
       63 天前
    @Earsum 但是大佬,纯老版本能用网易 UU 加速器,安装 4 个 nft 插件还是不能用。
    Earsum
        8
    Earsum  
       62 天前
    @sq123 这个我就不太清楚了,因为我个人没开源洁癖,用的是 lean's lede 源码
    sq123
        9
    sq123  
       62 天前
    @Earsum 好吧,谢谢。我现在还在用 R7800 (等 wifi7 大推广普及后再换),lede 的 ipq806X 的 ath10k-ct 有问题,每次编译失败,只能用官方的了,官方的 23.05.4 安 4 个插件打开 UU 加速游戏还是像没安装一样,手机 APP 一点就加速失败,看来只能放弃用手机热点将就了!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2703 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 13:26 · PVG 21:26 · LAX 06:26 · JFK 09:26
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.