8-ipset实现网站过滤

iptables只能根据ip地址进行转发,不能识别域名,而dnsmasq-full不仅可以实现域名-IP的映射,还可以把这个映射关系存储在ipset中,所以使用dnsmasq+ipset就可以实现iptables对域名的转发,可以实现很多功能

原理很简单,就是Dnsmasq接收到一个DNS查询请求,首先匹配配置文件中的域名列表,如果匹配成功某域名,就把IP的查询结果存储在一个或几个ipset集合中,然后使用iptables对这个ipset中的全部ip进行匹配并做相应的处理,如DROP或者REDIRECT或者设置mark

Dnsmasq+ipset+iptables基于域名的流量管理:
https://blog.csdn.net/lvshaorong/article/details/52981169

iptables -t mangle -I PREROUTING -m set --match-set wechat dst -j DROP
iptables -t mangle -D PREROUTING -m set --match-set wechat dst -j DROP
iptables -t mangle -I PREROUTING -m set --match-set video dst -j DROP
iptables -t mangle -D PREROUTING -m set --match-set video dst -j DROP

zipset/Makefile

include $(TOPDIR)/rules.mk

PKG_NAME:=zipset
PKG_VERSION:=1.0
PKG_RELEASE:=2019.07.31

PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)

include $(INCLUDE_DIR)/package.mk

define Package/$(PKG_NAME)
  SECTION:=ZIHOME
  CATEGORY:=ZIHOME
  DEPENDS:=+dnsmasq_full_ipset +ipset
  TITLE:=ZIHOME ipset scripts
  PKGARCH:=all
  SUBMENU:=net
endef

define Package/$(PKG_NAME)/description
 ZIHOME ipset.
endef

define Build/Prepare
endef

define Build/Configure
endef

define Build/Compile
endef

define Package/$(PKG_NAME)/install
    $(INSTALL_DIR) $(1)
    $(CP) ./files/* $(1)/
endef

$(eval $(call BuildPackage,$(PKG_NAME)))

zipset/files/etc/init.d/zipset

#!/bin/sh /etc/rc.common

START=40

start()
{
    local f n

    cd /etc/zihome-dnsmasq.d || return 0
    files="$(ls)"
    for f in *.ipset; do
        if [ ! -f $f ]; then
            continue
        fi
        n=${f%.ipset}
        ipset -! create $n hash:net || continue
        ipset flush $n || continue
    done
}

stop()
{
    local f n

    cd /etc/zihome-dnsmasq.d || return 0
    files="$(ls)"
    for f in *.ipset; do
        if [ ! -f $f ]; then
            continue
        fi
        n=${f%.ipset}
        ipset flush $n 2>/dev/null
        ipset destroy $n 2>/dev/null
    done
}

zipset/files/etc/zihome-dnsmasq.d/wechat.ipset

ipset=/v.qq.com/video
ipset=/video.qq.com/video
ipset=/ke.qq.com/video
ipset=/iqiyi.com/video
ipset=/tv.sohu.com/video
ipset=/youku.com/video
ipset=/tudou.com/video
ipset=/mgtv.com/video
ipset=/tv.cctv.com/video
ipset=/v.baidu.com/video
ipset=/bilibili.com/video
ipset=/v.pptv.com/video
ipset=/v.ifeng.com/video
ipset=/baofeng.com/video
ipset=/douyin.com/video
ipset=/ixigua.com/video

爱奇艺

123.125.111.85
36.110.238.90
124.64.199.173
111.202.75.89
119.249.58.216
124.64.199.37
111.202.75.27
124.64.199.177
119.249.58.212
119.249.58.218
202.108.14.116
123.125.111.111
124.64.199.179
124.64.198.191
123.125.111.70
123.125.111.84
111.206.70.152
111.206.70.132
111.206.70.153
119.249.58.213
101.72.202.218
202.108.14.117
119.249.58.217
111.202.75.109
101.72.202.211
111.202.74.189
124.64.199.232
119.249.58.211
202.108.14.140
101.72.202.214
101.72.202.213
119.249.58.215
111.206.70.130
111.202.75.18
111.202.75.68
123.125.115.196
101.72.202.216
119.249.58.214
125.39.12.5
111.206.13.22
111.202.75.57
111.206.23.96
111.202.74.192
101.72.202.217
123.125.111.100
123.125.111.81
202.108.14.143
124.64.199.181
106.38.219.16
111.206.23.97
123.125.84.228
124.64.199.175
111.202.75.29
61.240.130.161
111.202.74.191
111.206.70.199
111.202.75.92
101.227.21.91
123.125.111.117
111.202.75.9
111.206.70.161
111.206.70.144
124.64.198.209
123.125.111.71
111.206.70.214
116.211.189.222
124.64.198.195
101.227.21.92
202.108.14.150
111.202.74.190
101.72.202.212
61.240.130.162
111.206.70.205
202.108.14.145
111.202.75.80
111.202.75.102
111.206.70.133
101.72.202.215

抖音与西瓜一起

124.165.219.248
175.20.90.213
119.249.58.214
175.20.82.250
121.18.239.211
124.165.219.245
111.161.117.1
116.136.150.1
124.166.234.58
139.215.130.233
124.166.234.53
218.60.51.3
175.20.82.246
221.195.244.230
222.161.248.244
120.52.72.102
218.60.51.5
125.39.12.5
222.161.248.242
221.195.195.241
139.215.130.231
124.165.219.244
60.215.125.100
175.20.82.243
103.135.80.130
60.221.194.224
124.165.219.250
221.194.147.230
139.215.130.232
101.28.133.99
60.9.4.222
119.249.58.216
124.165.219.242
218.24.17.1
221.195.195.243
222.161.248.245
124.163.195.218
175.20.90.215
139.215.130.226
222.161.248.248
121.29.9.87
221.195.195.249
119.249.58.212
60.28.125.1
182.118.0.248
119.249.58.218
222.161.248.250
124.166.234.55
221.195.195.242
222.161.248.243
175.20.90.211
139.215.225.60
221.195.195.240
175.20.90.214
175.20.90.218
218.60.51.6
124.165.219.243
61.134.110.35
218.60.51.7
116.136.135.224
124.166.236.226
119.249.58.213
139.215.130.227
175.20.90.212
124.165.219.249
175.20.82.248
124.166.234.59
101.28.134.46
139.215.130.228
101.28.134.48
124.165.219.246
139.215.130.229
175.20.90.217
218.60.51.4
218.60.51.2
139.215.130.230
116.136.134.84
120.52.72.103
119.249.48.185
175.20.82.245
119.249.58.211
218.60.51.1
103.135.80.131
60.28.124.1
60.222.12.2
221.195.195.244
61.240.28.1
119.249.58.217
175.20.82.242
110.249.197.232
222.161.248.246
60.215.125.102
175.20.82.249
119.249.58.215
101.72.202.216
221.195.195.250
103.135.80.129
222.161.248.249
221.194.149.1
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在SpringBoot中添加IP过滤器有多种配置方式。一种常见的方式是使用注解@WebFilter配合@ServletComponentScan注解来配置过滤器。首先,在过滤器类上添加@WebFilter注解,并通过urlPatterns属性指定需要过滤的路径。然后,在启动类上添加@ServletComponentScan注解,并通过basePackages属性指定扫描的包路径。这样就可以实现IP过滤器的配置。\[1\]\[2\] 另一种方式是使用JavaConfig的方式创建过滤器。首先创建一个配置类,使用@Configuration注解标记,并在该类中使用@Bean注解创建FilterRegistrationBean对象。在该对象的filter属性中设置过滤器实例,通过setOrder方法设置执行顺序,通过addUrlPatterns方法设置过滤的请求路径。最后将FilterRegistrationBean对象返回。这样就可以实现IP过滤器的配置。\[3\] 需要注意的是,如果使用外部Tomcat启动,需要重写init()和destroy()方法,否则可能会启动失败。另外,如果在外部Tomcat启动时需要注入对象,需要进行特殊处理。使用@WebFilter无法使用@Order或Ordered进行执行顺序控制,使用@Component无法控制请求过滤路径。\[3\] 综上所述,以上是SpringBoot添加IP过滤器的几种配置方式。您可以根据具体需求选择适合的方式进行配置。 #### 引用[.reference_title] - *1* *3* [SpringBoot | SpringBoot多种 Filter过滤器 配置方式](https://blog.csdn.net/qq825478739/article/details/125421560)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [springBoot添加自定义过滤器Filter](https://blog.csdn.net/weixin_41996632/article/details/88562757)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值