OpenWRT 禁止指定设备获取IPV6地址

202次阅读
没有评论

共计 1851 个字符,预计需要花费 5 分钟才能阅读完成。

背景

家中部分设备需要IPV6,但是家人的网络设备,例如手机、电视等,在获取IPV6后往往会引发其他问题。

通过 iptables 控制设备获取V6 IP最为方便。

固件版本:OpenWrt R24.10.5 / LuCI Master (git-24.264.48010-ddbc5ea)

内核版本:6.1.112

实践

先确认LAN接口在系统内的标志,本文为 br-lan​。

DHCP配置

# cat /etc/config/dhcp
...
config dhcp 'lan'
        option interface 'lan'
        option start '100'  
        option limit '150'  
        option leasetime '12h'
        option dhcpv4 'server'
        list ra_flags 'managed-config'
        list ra_flags 'other-config'  
        option ra 'server'        
        option dhcpv6 'server'    
        option ra_slaac '0'     
        option ra_other '0'   
        option ra_management '2'
...

配置解释:

  • option ra ‘server’:此设备将作为RA的服务器,向连接到LAN接口的设备发送RA消息
  • option dhcpv6 ‘server’:启用DHCPv6服务器
  • option ra_slaac ‘0’:禁用SLAAC,拒绝设备通过路由器发送的RA消息自动生成IPv6地址
  • option ra_other ‘0’:客户端不使用DHCPv6来获取除IPv6地址之外的其他配置信息
  • option ra_management ‘2’:有状态的,表示客户端应该完全通过DHCPv6获取其IPv6地址

防火墙配置

防火墙策略上下顺序需严格遵守,首先允许特定的MAC地址,然后在最后添加默认的DROP规则。

黑白名单是互斥的做法,按需选择一种。

先给自定义策略文件加权:

chmod +x /etc/firewall.user

按下文示例修改规则完毕后,手动重启防火墙:

/etc/init.d/firewall restart

DHCP V6 租约默认12h,并不会由于防火墙重启而过期。

已经分配到 V6 IP 的客户端设备,需要在客户端手动重启网络或重新执行 dhcp 才能重新分配 IP。

白名单

由于默认规则是放行流量,所以配置白名单时需要在最后添加拒绝所有流量的策略。

以多个 mac 地址为例,仅允许指定设备获取IPV6:

# cat /etc/firewall.user
ip6tables -A input_lan_rule -i br-lan -p ipv6-icmp -m mac --mac-source de:47:f9:10:30:1d -j ACCEPT
ip6tables -A input_lan_rule -i br-lan -p udp --dport 547 -m mac --mac-source de:47:f9:10:30:1d -j ACCEPT

ip6tables -A input_lan_rule -i br-lan -p ipv6-icmp -m mac --mac-source bc:24:11:0e:e1:ec -j ACCEPT
ip6tables -A input_lan_rule -i br-lan -p udp --dport 547 -m mac --mac-source bc:24:11:0e:e1:ec -j ACCEPT

ip6tables -A input_lan_rule -i br-lan -p ipv6-icmp -j DROP
ip6tables -A input_lan_rule -i br-lan -p udp --dport 547 -j DROP

黑名单

以多个 mac 地址为例,禁止指定设备获取IPV6:

ip6tables -A input_lan_rule -i br-lan -p ipv6-icmp -m mac  --mac-source de:47:f9:10:30:1d -j DROP
ip6tables -A input_lan_rule -i br-lan -p udp --dport 547 -m mac  --mac-source de:47:f9:10:30:1d -j DROP

ip6tables -A input_lan_rule -i br-lan -p ipv6-icmp -m mac  --mac-source bc:24:11:0e:e1:ec -j DROP
ip6tables -A input_lan_rule -i br-lan -p udp --dport 547 -m mac  --mac-source bc:24:11:0e:e1:ec -j DROP
正文完
 
pengyinwei
版权声明:本站原创文章,由 pengyinwei 2024-11-12发表,共计1851字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处:https://www.opshub.cn
评论(没有评论)