Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在路由器上使用Tun模式做透明代理后,内网的服务器无法被外网访问到 #2549

Open
4 of 5 tasks
zlm324 opened this issue Feb 7, 2025 · 3 comments
Open
4 of 5 tasks

Comments

@zlm324
Copy link

zlm324 commented Feb 7, 2025

操作系统

Linux

系统版本

openwrt 23.05

安装类型

sing-box 原始命令行程序

如果您使用图形客户端程序,请提供该程序版本。

No response

版本

sing-box version 1.12.0-alpha.4

描述

网络是家里的内网,openwrt做软路由,在openwrt中做了端口转发:
protocol: any, source zone: wan, destination zone: lan, internal ip: 192.168.2.5
内网中有个服务器,ip地址是192.168.2.5,在此设置下,外网是可以访问到内网服务器的。

然后在openwrt中使用sing-box做透明代理,tun模式,运行后代理功能正常,但外网无法访问到内网服务器。

重现方式

配置文件如下:

{
    "dns": {
        "servers": [
            {
                "tag": "dns_direct",
                "type": "tls",
                "server": "223.5.5.5",
                "detour": "out_direct"
            },
            {
                "tag": "dns_proxy",
                "type": "tls",
                "server": "8.8.8.8",
                "detour": "out_selector"
            }
        ]
     },
    "inbounds": [
        {
            "tag": "in_tun",
            "type": "tun",
            "address": ["172.19.0.1/30"],
            "route_exclude_address": ["192.168.2.0/16"],
            "auto_route": true,
            "auto_redirect": true,
            "strict_route": true,
            "stack": "mixed"
        }
    ],
    "outbounds": [
        {
            "tag": "out_1",
            "type": "vless"
        },
        {
            "tag": "out_2",
            "type": "vless"
        },
        {
            "tag": "out_3",
            "type": "vless"
        },
        {
            "type": "selector",
            "tag": "out_selector",
            "outbounds": ["out_urltest", "out_1", "out_2", "out_3"],
            "default": "out_urltest"
        },
        {
            "type": "urltest",
            "tag": "out_urltest",
            "outbounds": ["out_1", "out_2", "out_3"],
            "url": "https://connectivitycheck.gstatic.com/generate_204",
            "interval": "5m",
            "tolerance": 150
        },
        {
            "tag": "out_direct",
            "type": "direct",
            "domain_resolver": "dns_direct"
        }
    ],
    "route": {
        "rule_set": [
            {
                "tag": "geosite-geolocation-cn",
                "type": "remote",
                "format": "binary",
                "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-geolocation-cn.srs",
                "download_detour": "out_selector"
            },
            {
                "tag": "geosite-cn",
                "type": "remote",
                "format": "binary",
                "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-cn.srs",
                "download_detour": "out_selector"
            },
            {
                "tag": "geoip-cn",
                "type": "remote",
                "format": "binary",
                "url": "https://raw.githubusercontent.com/SagerNet/sing-geoip/rule-set/geoip-cn.srs",
                "download_detour": "out_selector"
            },
            {
                "tag": "ads",
                "type": "remote",
                "format": "binary",
                "url": "https://raw.githubusercontent.com/REIJI007/AdBlock_Rule_For_Sing-box/main/adblock_reject.srs",
                "download_detour": "out_selector"
            }
        ],
        "rules": [
            {
                "action": "resolve",
                "strategy": "prefer_ipv4"
            },
            {
                "action": "sniff",
                "timeout": "500ms"
            },
            {
                "type": "logical",
                "mode": "or",
                "rules": [{"port": 53}, {"protocol": "dns"}],
                "action": "hijack-dns"
            },
            {
                "type": "logical",
                "mode": "or",
                "rules": [{"protocol": "stun"}, {"protocol": "udp"}, {"protocol": "quic"}],
                "outbound": "out_direct"
            },
            {
                "ip_is_private": true,
                "outbound": "out_direct"
            },
            {
                "rule_set": ["ads"],
                "action": "reject"
            },
            {
                "rule_set": ["geosite-geolocation-cn", "geosite-cn", "geoip-cn"],
                "outbound": "out_direct"
            }
        ],
        "default_domain_resolver": "dns_direct",
        "final": "out_selector",
        "auto_detect_interface": true
    },
    "experimental": {
        "cache_file": {"enabled": true}
    }
}

使用以上配置文件,未对openwrt做其他设置,sing-box运行后代理功能正常,同时外网无法访问到192.168.2.5的内网服务器,停止sing-box后,外网恢复访问。

日志

sing-box运行后,外网访问内网服务器,服务器的nginx日志文件中能找到如下记录:
<外网设备ip> - - [07/Feb/2025:17:35:01 +0800] "GET /assets/index.c4c82a28.css HTTP/1.1" 200 19954 "https://<外网访问地址>" "Mozilla/5.0 (Android 15; Mobile; rv:133.0) Gecko/133.0 Firefox/133.0" "-"
在sing-box的debug级别的日志中,找不到与<外网设备ip><192.168.2.5>相关的记录。

支持我们

完整性要求

  • 我保证阅读了文档,了解所有我编写的配置文件项的含义,而不是大量堆砌看似有用的选项或默认值。
  • 我保证提供了可以在本地重现该问题的服务器、客户端配置文件与流程,而不是一个脱敏的复杂客户端配置文件。
  • 我保证提供了可用于重现我报告的错误的最简配置,而不是依赖远程服务器、TUN、图形界面客户端或者其他闭源软件。
  • 我保证提供了完整的配置文件与日志,而不是出于对自身智力的自信而仅提供了部分认为有用的部分。
@zlm324 zlm324 changed the title 在路由器上使用Tun模式做透明代理后,内网的服务器无法被外网访问到了。 在路由器上使用Tun模式做透明代理后,内网的服务器无法被外网访问到 Feb 7, 2025
@Mosney
Copy link

Mosney commented Feb 7, 2025

#2167 应该是同一个问题。我也被这个问题困扰很久。

最近跟r1和o1整了半天,想手动打个补丁用起来但是无果。在公网和内网主机上抓包可以看到SYN和ACK记录,现象与你一致。目前能确定的是DNAT正常,即防火墙的端口转发规则实际还是生效的,内网服务器能收到从公网wan侧发来的请求,但返回的数据包似乎又重新进了tun,sing-box开debug级别没有内网主机做出响应返回的连接日志,发起请求的公网侧主机收不到响应不断重连直到超时失败。

另外还有个观察变量不唯一因此不一定对:1.10和早期的1.11-alpha版本IPv4受影响但IPv6正常,在公网侧WireGuard和luci都可以通过IPv6地址正常访问,直到目前1.11.1似乎IPv6也开始受影响了,上述两个场景不再可用。

@zlm324
Copy link
Author

zlm324 commented Feb 8, 2025

#2167 应该是同一个问题。我也被这个问题困扰很久。

最近跟r1和o1整了半天,想手动打个补丁用起来但是无果。在公网和内网主机上抓包可以看到SYN和ACK记录,现象与你一致。目前能确定的是DNAT正常,即防火墙的端口转发规则实际还是生效的,内网服务器能收到从公网wan侧发来的请求,但返回的数据包似乎又重新进了tun,sing-box开debug级别没有内网主机做出响应返回的连接日志,发起请求的公网侧主机收不到响应不断重连直到超时失败。

另外还有个观察变量不唯一因此不一定对:1.10和早期的1.11-alpha版本IPv4受影响但IPv6正常,在公网侧WireGuard和luci都可以通过IPv6地址正常访问,直到目前1.11.1似乎IPv6也开始受影响了,上述两个场景不再可用。

对的,就是像你说的这样。内网服务器能收到请求,但返回的数据就没能到外网,有没有再次进入tun不是很清楚,毕竟debug日志中也没看到有内网机器的连接,这数据包去哪了呢?还有一个情况是,如果我把"route_exclude_address"这一句去掉,整个内网就访问不了外网了,这又是为啥?

@jackadam1981
Copy link

我也遇到了,但是v6路由器可以访问。
看到2167是写了bug,等更新。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants