惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - 聂微东
IT之家
IT之家
GbyAI
GbyAI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Y
Y Combinator Blog
博客园 - 【当耐特】
The Cloudflare Blog
宝玉的分享
宝玉的分享
罗磊的独立博客
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
Visual Studio Blog
小众软件
小众软件
博客园_首页
Last Week in AI
Last Week in AI
J
Java Code Geeks
V
V2EX
雷峰网
雷峰网
Apple Machine Learning Research
Apple Machine Learning Research
阮一峰的网络日志
阮一峰的网络日志
腾讯CDC
博客园 - 司徒正美
Engineering at Meta
Engineering at Meta
The GitHub Blog
The GitHub Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
D
DataBreaches.Net
博客园 - 三生石上(FineUI控件)
MyScale Blog
MyScale Blog
云风的 BLOG
云风的 BLOG
The Register - Security
The Register - Security
M
MIT News - Artificial intelligence
Microsoft Azure Blog
Microsoft Azure Blog
T
The Blog of Author Tim Ferriss
N
Netflix TechBlog - Medium
F
Full Disclosure
B
Blog
H
Help Net Security
C
Check Point Blog
WordPress大学
WordPress大学
人人都是产品经理
人人都是产品经理
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Jina AI
Jina AI
酷 壳 – CoolShell
酷 壳 – CoolShell
Blog — PlanetScale
Blog — PlanetScale
L
LangChain Blog
P
Proofpoint News Feed
D
Docker
Microsoft Security Blog
Microsoft Security Blog

Dallas Lu

邮件服务的域名成功从 SURBL 黑名单移除 网站多语言的设计细节 网站评论系统的目前进展和展望 在公网使用 iptables 转发端口时保留客户端 IP 邮件投递平台 Postal 的使用经验 自建 Postal 完美替代 SendGrid 互联网在崩塌吗,然后呢 在 SvelteKit 应用中使用 JSON-LD 网页的打印样式应该怎么写 “茴字的四种写法”之 IP 与域名 怎么伪造 Git 提交的时区 供大众交流的论坛和其它替代产品还是不好用 改编不是照搬 一次排查诡异的网络问题的经历 使用自建 Tabby Web 来同步 Tabby 配置 手动建立自己的 IPv6 Tunnel 服务 在 PVE 手动配置网络及虚拟机 IPv6 公网 在 PVE 中缩小 Ubuntu 虚拟机的磁盘 Beancount 摊销与折旧的使用以及相关插件
在 OpenWRT 23 中使用 nftset 配置 Shadowsocks 规则
达拉斯・卢 · 2024-03-18 · via Dallas Lu

在 OpenWRT 23 中,默认使用的防火墙是 fw4;nftables 对应的的是 nftset。本文介绍使用 dnsmasq-full/nftset/nftables 为 shadowsocks redir 创建基于 gfwlist 的规则。

nftables

编辑 /etc/nftables.d/gfwlist.nft,设置 nftset 的初始配置,加入了 Telegram 的 IP 段,以及转发规则1

set gfwlist {
	type ipv4_addr
	flags interval
	elements = {
		# telegram start
		91.105.192.0/23,
		91.108.4.0/22,
		91.108.8.0/22,
		91.108.12.0/22,
		91.108.16.0/22,
		91.108.20.0/22,
		91.108.56.0/22,
		149.154.160.0/20,
		185.76.151.0/24,
		#telegram end
	}
}

chain gfwlist-redirect {
	type nat hook prerouting priority 0; policy accept;
	ip daddr @gfwlist ip protocol tcp redirect to :1100
}

以上配置假设 ss-redir 监听的端口是 1100。重启防火墙:

service firewall restart

手动配置

临时将 IP 加入 gfwlist 或从 gfwlist 移出2

nft add element inet fw4 gfwlist { 1.2.3.4 }
nft delete element inet fw4 gfwlist { 1.2.3.4 }

Dnsmasq

切换为 dnsmasq-full

opkg remove dnsmasq
opkg install dnsmasq-full

service dnsmasq restart

创建 dnsmasq 配置文件

默认的配置目录是 /tmp/dnsmasq.d,所以我们最好将配置文件放在另外一个位置:

mkdir -p /root/gfwlist/nftset

并在启动时,自动复制配置文件:

cp -f /root/gfwlist/nftset/*.conf /tmp/dnsmasq.d

手动配置

如果我们有一个手动维护的配置文件 /root/gfwlist/nftset/dnsmasq_gfwlist_nftset_custom.conf

server=/githubusercontent.com/127.0.0.1#5353
nftset=/githubusercontent.com/4#inet#fw4#gfwlist
server=/github.com/127.0.0.1#5353
nftset=/github.com/4#inet#fw4#gfwlist

创建部署脚本 deploy-dnsmasq-conf.sh:

cp -f /root/gfwlist/nftset/*.conf /tmp/dnsmasq.d && service dnsmasq restart

gfwlist

将 gfwlist 转化为 dnsmasq 配置文件的脚本 gfwlist2dnsmasq.sh 只支持 ipset,需要进行一些编辑:

- ipset=/\1/'$IPSET_NAME'#g' > $CONF_TMP_FILE
+ nftset=/\1/4\#inet\#fw4\#'$IPSET_NAME'#g' > $CONF_TMP_FILE

将其写入到脚本文件 /root/gfwlist/nftset/gfwlist2dnsmasq-nftset.sh 中。另建立 update-gfwlist-dnsmasq-conf.sh

sh /root/gfwlist/nftset/gfwlist2dnsmasq-nftset.sh -s gfwlist -o /root/gfwlist/nftset/dnsmasq_gfwlist_nftset.conf && /root/gfwlist/nftset/deploy-dnsmasq-conf.sh

编辑 /etc/rc.local,加入:

sh /root/gfwlist/nftset/update-gfwlist-dnsmasq-conf.sh

添加 crontab 任务:

0 0 1 * * ?     sh /root/gfwlist/nftset/update-gfwlist-dnsmasq-conf.sh

结语

网上的文章多以翻墙为例,本文内容也选择了这一场景。实际上,另一个有用的场合是使用住宅 IP 访问 ChatGPT 等服务。


  1. 99010. dnsmasq-full + nftset + nftables透明代理. 恩山无线论坛. 2023. ↩

  2. 10.5. 使用 nftables 命令中的集合. Red Hat. ↩