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

openwrt 如何只让内网中指定的设备才能获取到 slaac ipv6

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

    如题,不想给内网设备有公网 ipv6 地址,但是部分设备又需要 我知道可以批量关闭其他所有设备的 ipv6 选项(太麻烦了

    8 条回复    2023-11-12 10:40:51 +08:00
    a90405
        1
    a90405  
       176 天前
    # 下面的代码中 mac1 mac2 mac3 是你想获得 ipv6 地址的客户端的 mac 地址,自己换上就行了,想更多加个,号继续填就行了

    nft insert rule inet fw4 mangle_prerouting meta nfproto ipv6 udp dport 547 ether saddr !={ mac1, mac2, mac3 } counter drop comment \" 阻止 dhcpv6 \"

    nft insert rule inet fw4 mangle_prerouting icmpv6 type { 133-143 } ether saddr !={ mac1, mac2, mac3 } counter drop comment \" 阻止 slaac \"
    mikususu33
        2
    mikususu33  
    OP
       176 天前
    @a90405 大佬牛逼,可以提供 ip6tables 版本的吗
    a90405
        3
    a90405  
       176 天前
    @mikususu33

    ipset create ipv6macs hash:mac
    ipset add ipv6macs mac1
    ipset add ipv6macs mac2
    ipset add ipv6macs mac3

    ip6tables -I input_lan_rule -p ipv6-icmp -m set ! --match-set ipv6macs src -j DROP
    ip6tables -I input_lan_rule -p udp --dport 547 -m set ! --match-set ipv6macs src -j DROP

    没有环境,没测试过,你试试
    mikususu33
        4
    mikususu33  
    OP
       176 天前
    @a90405 使用了这个之后,依旧所有设备正常获取 ipv6 地址,只是只有指定设备才可以联网,请问有办法让其他设备不获取到 ipv6 地址吗
    a90405
        5
    a90405  
       176 天前
    @mikususu33
    ipset create ipv6macs hash:mac
    ipset add ipv6macs mac1
    ipset add ipv6macs mac2
    ipset add ipv6macs mac3

    ip6tables -t mangle -I PREROUTING -i br-lan -p ipv6-icmp -m set ! --match-set ipv6macs src -j DROP
    ip6tables -t mangle -I PREROUTING -i br-lan -p udp --dport 547 -m set ! --match-set ipv6macs src -j DROP

    刚特地下了个 lean 版本的测试了,上面的防火墙规则,确保可行,把上面的代码,复制到 自定义防火墙规则 里面,mac 1 mac2 mac3 替换成需要获取 ipv6 的机器。
    a90405
        6
    a90405  
       176 天前
    @mikususu33
    -i br-lan 这里,如果你的局域网接口不是 br-lan 这个设备,请自己替换 br-lan 为指定的接口。
    mikususu33
        7
    mikususu33  
    OP
       171 天前
    @a90405 其他设备还是可以正常获取 ipv6,只是 v6 不能联网,还是干扰了内网,这个有办法吗
    a90405
        8
    a90405  
       171 天前 via Android
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2234 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 11:13 · PVG 19:13 · LAX 04:13 · JFK 07:13
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.