找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
广告投放联系QQ68610888
查看: 7335|回复: 15

Openwrt使用Sing-box TUN模式无感代理

[复制链接]
本帖最后由 eam007 于 2023-12-5 01:34 编辑

测试环境
树莓派3B,不知明X86_64小主机一台内置Emmc。

系统
Openwrt 官方包,更换软件包源为清华

安装sing-box
  1. opkg update
  2. opkg install kmod-inet-diag kmod-netlink-diag kmod-tun kmod-tcp-bbr
  3. opkg install sing-box curl nano
复制代码


在/etc/config/firewall中添加规则
  1. config zone
  2.         option name 'proxy'
  3.         option forward 'REJECT'
  4.         option output 'ACCEPT'
  5.         option input 'ACCEPT'
  6.         option mtu_fix '1'
  7.         option device 'tun0'
  8.         list network 'proxy'

  9. config forwarding
  10.         option name 'lan-proxy'
  11.         option dest 'proxy'
  12.         option src 'lan'
复制代码


添加网络接口/etc/config/firewall
  1. config interface 'proxy'
  2.         option proto 'none'
  3.         option device 'tun0'
复制代码


修改sing-box开机启动/etc/config/sing-box
  1. config sing-box 'main'
  2.         option enabled '1'
  3.         option user 'root'
  4.         option conffile '/etc/sing-box/config.json'
  5.         option workdir '/usr/share/sing-box'
复制代码

sing-box配置说明,目前测试TUIC能正常使用。

TUN入站配置:
  1.   "inbounds": [
  2.     {
  3.       "type": "tun",
  4.       "tag": "tun-in",
  5.       "interface_name": "tun0",
  6.       "mtu": 9000,
  7.       "inet4_address": "172.19.0.1/30",
  8.       "auto_route": true,
  9.       "stack": "system",
  10.       "sniff": true,
  11.       "sniff_override_destination": true
  12.     }
  13.   ],
复制代码

我的恩山、我的无线 The best wifi forum is right here.
值得mark一下
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| | 显示全部楼层
本帖最后由 eam007 于 2023-12-5 01:44 编辑

有关config.json配置示例:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

我用上最新版本的sing-box,千兆网测速下来只有200M,不知道是否配置json有问题,还是防火墙没有配置好,静等op版本的客户端出来。homeproxy可以用,但是无法去广告,郁闷中,小白一个研究好久了!
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

可以参考以下教程,tun模式可以直接照抄,我是自己改的tproxy模式
https://github.com/rezconf/Sing-box/wiki/How-to-Run

点评

能否参考tproxy怎么设置呢? 如果光猫是192.168.1.1,家里的openwrt是192.168.10.1。 谢谢。  详情 回复 发表于 2024-2-5 22:17
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

学习一下,感谢分享
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

bxyun 发表于 2024-1-10 23:56
可以参考以下教程,tun模式可以直接照抄,我是自己改的tproxy模式
https://github.com/rezconf/Sing-box/wi ...

能否参考tproxy怎么设置呢?

如果光猫是192.168.1.1,家里的openwrt是192.168.10.1。

谢谢。

点评

https://xtls.github.io/document/level-2/tproxy_ipv4_and_ipv6.html 将命令写入脚本执行或者直接写入启动项  详情 回复 发表于 2024-2-6 13:11
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

delphinus 发表于 2024-2-5 22:17
能否参考tproxy怎么设置呢?

如果光猫是192.168.1.1,家里的openwrt是192.168.10.1。

https://xtls.github.io/document/level-2/tproxy_ipv4_and_ipv6.html
将命令写入脚本执行或者直接写入启动项

点评

试了几次都有问题,加上sing-box里mark不知怎么打,只好放有每个outbound与direct。  详情 回复 发表于 2024-2-6 23:56
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

bxyun 发表于 2024-2-6 13:11
https://xtls.github.io/document/level-2/tproxy_ipv4_and_ipv6.html
将命令写入脚本执行或者直接写入启 ...

试了几次都有问题,加上sing-box里mark不知怎么打,只好放有每个outbound与direct。

点评

# iptables rules ip route add local default dev lo table 100 ip rule add fwmark 1 table 100 # 可选IPV6 ip -6 route add local default dev lo table 106 ip -6 rule add fwmark 1 table 106 iptables -t ma  详情 回复 发表于 2024-2-7 12:10
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

delphinus 发表于 2024-2-6 23:56
试了几次都有问题,加上sing-box里mark不知怎么打,只好放有每个outbound与direct。
...

# iptables rules
ip route add local default dev lo table 100
ip rule add fwmark 1 table 100

# 可选IPV6
ip -6 route add local default dev lo table 106
ip -6 rule add fwmark 1 table 106

iptables -t mangle -N SING
iptables -t mangle -A SING -d 0.0.0.0/8 -j RETURN
iptables -t mangle -A SING -d 10.0.0.0/24 -j RETURN
iptables -t mangle -A SING -d 127.0.0.1/32 -j RETURN
iptables -t mangle -A SING -d 192.0.0.0/24 -j RETURN
iptables -t mangle -A SING -d 224.0.0.0/4 -j RETURN
iptables -t mangle -A SING -d 255.255.255.255/32 -j RETURN
iptables -t mangle -A SING -d 192.168.0.0/16 -p tcp -j RETURN #改为自己所用地址段
iptables -t mangle -A SING -d 192.168.0.0/16 -p udp ! --dport 53 -j RETURN #改为自己所用地址段
iptables -t mangle -A SING -j RETURN -m mark --mark 0xff
iptables -t mangle -A SING -p udp -j TPROXY --on-ip 127.0.0.1 --on-port 2053 --tproxy-mark 1 #改为自己的端口
iptables -t mangle -A SING -p tcp -j TPROXY --on-ip 127.0.0.1 --on-port 2053 --tproxy-mark 1 #改为自己的端口
iptables -t mangle -A PREROUTING -j SING

# 可选IPV6
ip6tables -t mangle -N SING6
ip6tables -t mangle -A SING6 -d ::1/128 -j RETURN
ip6tables -t mangle -A SING6 -d fe80::/10 -j RETURN
ip6tables -t mangle -A SING6 -d fd00::/8 -p tcp -j RETURN
ip6tables -t mangle -A SING6 -d fd00::/8 -p udp ! --dport 53 -j RETURN
ip6tables -t mangle -A SING6 -j RETURN -m mark --mark 0xff
ip6tables -t mangle -A SING6 -p udp -j TPROXY --on-ip ::1 --on-port 2053 --tproxy-mark 1 #改为自己的端口
ip6tables -t mangle -A SING6 -p tcp -j TPROXY --on-ip ::1 --on-port 2053 --tproxy-mark 1 #改为自己的端口
ip6tables -t mangle -A PREROUTING -j SING6

iptables -t mangle -N SING_MASK
iptables -t mangle -A SING_MASK -d 0.0.0.0/8 -j RETURN
iptables -t mangle -A SING_MASK -d 10.0.0.0/8 -j RETURN
iptables -t mangle -A SING_MASK -d 127.0.0.0/8 -j RETURN
iptables -t mangle -A SING_MASK -d 192.0.0.0/24 -j RETURN
iptables -t mangle -A SING_MASK -d 224.0.0.0/4 -j RETURN
iptables -t mangle -A SING_MASK -d 255.255.255.255/32 -j RETURN
iptables -t mangle -A SING_MASK -d 192.168.0.0/16 -p tcp -j RETURN #改为自己所用地址段
iptables -t mangle -A SING_MASK -d 192.168.0.0/16 -p udp ! --dport 53 -j RETURN #改为自己所用地址段
iptables -t mangle -A SING_MASK -j RETURN -m mark --mark 0xff
iptables -t mangle -A SING_MASK -p udp -j MARK --set-mark 1
iptables -t mangle -A SING_MASK -p tcp -j MARK --set-mark 1
iptables -t mangle -A OUTPUT -j SING_MASK

# 可选IPV6
ip6tables -t mangle -N SING6_MASK
ip6tables -t mangle -A SING6_MASK -d fe80::/10 -j RETURN
ip6tables -t mangle -A SING6_MASK -d fd00::/8 -p tcp -j RETURN
ip6tables -t mangle -A SING6_MASK -d fd00::/8 -p udp ! --dport 53 -j RETURN
ip6tables -t mangle -A SING6_MASK -j RETURN -m mark --mark 0xff
ip6tables -t mangle -A SING6_MASK -p udp -j MARK --set-mark 1
ip6tables -t mangle -A SING6_MASK -p tcp -j MARK --set-mark 1
ip6tables -t mangle -A OUTPUT -j SING6_MASK

iptables -t mangle -N DIVERT
iptables -t mangle -A DIVERT -j MARK --set-mark 1
iptables -t mangle -A DIVERT -j ACCEPT
iptables -t mangle -I PREROUTING -p tcp -m socket -j DIVERT

# 可选IPV6
ip6tables -t mangle -N DIVERT
ip6tables -t mangle -A DIVERT -j MARK --set-mark 1
ip6tables -t mangle -A DIVERT -j ACCEPT
ip6tables -t mangle -I PREROUTING -p tcp -m socket -j DIVERT

点评

对我帮助很大 多谢分享  发表于 2024-4-12 21:22

评分

参与人数 1恩山币 +1 收起 理由
hx*** + 1 我手抖了下,加分变扣分了!

查看全部评分

我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

添加网络接口/etc/config/firewall:
config interface 'proxy'
        option proto 'none'
        option device 'tun0'


是在  firewall 添加接口吗? network?
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

欢迎大家光临恩山无线论坛上一条 /1 下一条

有疑问请添加管理员QQ86788181|手机版|小黑屋|Archiver|恩山无线论坛(常州市恩山计算机开发有限公司版权所有) ( 苏ICP备05084872号 )

GMT+8, 2024-5-4 17:06

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

| 江苏省互联网有害信息举报中心 举报信箱:js12377 | @jischina.com.cn 举报电话:025-88802724 本站不良内容举报信箱:68610888@qq.com 举报电话:0519-86695797

快速回复 返回顶部 返回列表