openwrt实现url过滤

一、介绍
url过滤有多种方式
1、iptables的拓展模块string模块
效率不高,会影响通信速率

2、iptables的拓展模块webstr模块
只对http有效,https不行

3、dns拦截,修改/etc/dnsmasq.conf,将指定的url设置固定的ip
效率还行,就是不好实现白名单

4、dnsmasq+ipset+iptables
效率可以,黑白名单都能实现

二、实现
这里重点将第4种方式
1、配置dnsmasq.conf
修改/etc/dnsmasq.conf
conf-dir=/etc/dnsmasq.d

2、新建目录和文件
mkdir /etc/dnsmasq.d
touch /etc/dnsmasq.d/domain.conf

3、修改防火墙
ipset -N domain iphash
黑名单
iptables -t filter -A FORWARD -m set --match-set domain dst -j DROP
iptables -t filter -A FORWARD -m set --match-set domain src -j DROP
白名单
iptables -t filter -A FORWARD -m set --match-set domain dst -j ACCEPT
iptables -t filter -A FORWARD -m set --match-set domain src -j ACCEPT
iptables -t filter -A FORWARD -j DROP

4、添加过滤
修改’/etc/dnsmasq.d/domain.conf
ipset=/www.baidu.com/domain
ipset=/www.qq.com/domain

整个原理:dnsmasq会将/etc/dnsmasq.d/domain.conf的ur转换成ip丢给ipset集合,防火墙的配置决定了这些ip是否放行

注意:openwrt默认的dnsmasq不支持ipset,修改修改配置使用dnsmasq-full,并开启ipser支持才行,修改配置方法可以参考上篇文章
另外,需要本地设备将url的地址访问一下比如ping一下才能加进ipset集合里面,局域网设备访问不会自动加

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值