SagerNet / sing-box

The universal proxy platform
https://sing-box.sagernet.org/
Other
15.67k stars 1.92k forks source link

linux作为客户端使用tun无法对服务器进行访问 #1102

Closed zihelyu closed 7 months ago

zihelyu commented 7 months ago

Operating system

Linux

System version

debian

Installation type

Original sing-box Command Line

If you are using a graphical client, please provide the version of the client.

No response

Version

```console Environment: go1.21.3 linux/amd64 Tags: with_gvisor,with_quic,with_dhcp,with_wireguard,with_ech,with_utls,with_reality_server,with_clash_api Revision: 0abe9d38147cd4128b3ec34fbeafa825de7b4534 CGO: disabled ```

Description

使用sing-box run运行后tun代理正常工作,ssh也可以连接,但是nginx和mysql的端口只能从localhost能访问,不可以被外部访问了

Reproduction

配置文件

```console { "dns":{ "servers":[ { "tag":"google", "address":"tls://8.8.8.8" }, { "tag":"local", "address":"223.5.5.5", "detour":"direct" }, { "tag":"block", "address":"rcode://success" } ], "rules":[ { "geosite":"category-ads-all", "server":"block", "disable_cache":true }, { "outbound":"any", "server":"local" }, { "geosite":"cn", "server":"local" } ], "strategy":"ipv4_only" }, "inbounds":[ { "type":"tun", "inet4_address":"172.19.0.1/30", "auto_route":true, "strict_route":false, "sniff":true } ], "outbounds":[ { "tag":"proxy", "type":"vless", "server":"ip.com", "server_port":9999, "uuid":"uuid", "flow":"xtls-rprx-vision", "network":"tcp", "packet_encoding":"xudp", "tls":{ "enabled":true, "server_name":"apple.com", "utls":{ "enabled":true, "fingerprint":"safari" }, "reality":{ "enabled":true, "public_key":"public_key" } } }, { "type":"direct", "tag":"direct" }, { "type":"block", "tag":"block" }, { "type":"dns", "tag":"dns-out" } ], "route":{ "rules":[ { "protocol":"dns", "outbound":"dns-out" }, { "geosite":"cn", "geoip":[ "private", "cn" ], "outbound":"direct" }, { "geosite":"category-ads-all", "outbound":"block" } ], "auto_detect_interface":true } } ```

Logs

No response

zihelyu commented 7 months ago

Sorry, this problem is due to the docker network card

AlawnCN commented 7 months ago

感觉跟Docker网卡没关系,应该是Linux不支持作为Client使用Tun

hst-Sunday commented 2 months ago

@zihelyu 请教下,如何解决的?我也遇到同样问题了

zihelyu commented 2 months ago

@zihelyu请教下,如何解决的?我也遇到了同样的问题

strict_route设置为false,关闭严格路由就好了

hst-Sunday commented 2 months ago

@zihelyu

{
    "dns": {
        "servers": [
            {
                "tag": "google",
                "address": "tls://8.8.8.8"
            },
            {
                "tag": "local",
                "address": "223.5.5.5",
                "detour": "direct"
            }
        ],
        "rules": [
            {
                "geosite": "cn",
                "server": "local"
            }
        ],
        "strategy": "ipv4_only"
    },
    "inbounds": [
        {
            "type": "tun",
            "inet4_address": "172.19.0.1/30",
            "auto_route": true,
            "sniff": true,
            "strict_route":false
        }
    ],
    "outbounds": [
        {
            "type": "vmess",
            "tag": "hk",
            "server": "38.38.38.38",
            "server_port": 3838,
            "uuid": "803ef998-fbdd-2404-989f-cdb16482d3b9",
            "alter_id": 0,
            "security": "auto",
            "network": "tcp",
            "tcp_fast_open": false
        },
        {
            "type": "direct",
            "tag": "direct"
        },
        {
            "type": "block",
            "tag": "block"
        },
        {
            "type": "dns",
            "tag": "dns-out"
        }
    ],
    "route": {
        "rules": [
            {
                "protocol": "dns",
                "outbound": "dns-out"
            },
            {
                "geosite": "category-ads-all",
                "outbound": "block"
            },
            {
                "geosite": "cn",
                "geoip": "cn",
                "outbound": "direct"
            },
            {
                "domain_suffix": [
                    "google.com"
                ],
                "outbound": "hk"
            }
        ],
        "auto_detect_interface": true
    }
}

感谢回复。可我这样的配置 ,docker服务 外网还是访问不了

zihelyu commented 2 months ago

@zihelyu

{
    "dns": {
        "servers": [
            {
                "tag": "google",
                "address": "tls://8.8.8.8"
            },
            {
                "tag": "local",
                "address": "223.5.5.5",
                "detour": "direct"
            }
        ],
        "rules": [
            {
                "geosite": "cn",
                "server": "local"
            }
        ],
        "strategy": "ipv4_only"
    },
    "inbounds": [
        {
            "type": "tun",
            "inet4_address": "172.19.0.1/30",
            "auto_route": true,
            "sniff": true,
            "strict_route":false
        }
    ],
    "outbounds": [
        {
            "type": "vmess",
            "tag": "hk",
            "server": "38.38.38.38",
            "server_port": 3838,
            "uuid": "803ef998-fbdd-2404-989f-cdb16482d3b9",
            "alter_id": 0,
            "security": "auto",
            "network": "tcp",
            "tcp_fast_open": false
        },
        {
            "type": "direct",
            "tag": "direct"
        },
        {
            "type": "block",
            "tag": "block"
        },
        {
            "type": "dns",
            "tag": "dns-out"
        }
    ],
    "route": {
        "rules": [
            {
                "protocol": "dns",
                "outbound": "dns-out"
            },
            {
                "geosite": "category-ads-all",
                "outbound": "block"
            },
            {
                "geosite": "cn",
                "geoip": "cn",
                "outbound": "direct"
            },
            {
                "domain_suffix": [
                    "google.com"
                ],
                "outbound": "hk"
            }
        ],
        "auto_detect_interface": true
    }
}

感谢回复。可我这样的配置 ,docker服务 外网还是访问不了

试一下

"inbounds": [ { "type": "tun", "inet4_address": "172.19.0.1/30", "auto_route": true, "stack": "gvisor", "sniff": true } ]

hst-Sunday commented 2 months ago

@zihelyu

"inbounds": [
        {
        "type": "tun",
        "inet4_address": "172.19.0.1/30",
        "auto_route": true,
        "stack": "gvisor",
        "sniff": true
        }
]

试了也不行😭 +"strict_route": false 也不行