openwrt使用ipset+iptables建立一个简单的家庭网络管理功能

使用ipset建立三个hash表

ipset create direct_ip hash:net  #定向ip或域名
ipset create direct_blacklist_mac hash:mac #定向流量访问黑名单
ipset create auth_pass_mac hash:mac #认证通过终端的mac

设置路由规则

iptables -N AUTH_POLICY
iptables -N FLOW_POLICY
iptables -I FORWARD -j AUTH_POLICY
#没认证通过的mac,无法上网
iptables -I AUTH_POLICY -i br-lan -m set ! --match-set auth_pass_mac src -j DROP

#被拉黑的mac无法访问定向ip或域名
iptables -A AUTH_POLICY -i br-lan -m set --match-set direct_blacklist_mac src -j FLOW_POLICY
iptables -A FLOW_POLICY -i br-lan -m set --match-set direct_ip dst -j DROP

使用例子:

允许特定终端上网

#默认openwrt启动,配置好以上功能之后,所有的终端(mac)都无法上网

#这时我希望我自己可以上网,我电脑的mac为:00:11:22:33:44:55
ipset add auth_pass_mac 00:11:22:33:44:55
#让家里小孩的电脑上网,小孩电脑mac为:00:11:22:33:44:66
ipset add auth_pass_mac 00:11:22:33:44:66
#不让小孩上网
ipset del auth_pass_mac 00:11:22:33:44:66

不让小孩访问特定网址:游戏或视频等

#将小孩电脑放进定向流量访问黑名单
ipset add direct_blacklist_mac 00:11:22:33:44:66
#不让小孩访问 www.bilibili.com
ipset add direct_ip www.bilibili.com

ipset详细介绍网址

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值