v2fly / v2ray-core

A platform for building proxies to bypass network restrictions.
https://v2fly.org
MIT License
28.52k stars 4.55k forks source link

透明代理无法使用 fakedns #2973

Open nie11kun opened 3 months ago

nie11kun commented 3 months ago

你正在使用哪个版本的 V2Ray?

5.15.3

你的使用场景是什么?

openwrt 配置透明代理

你看到的异常现象是什么?

配置了透明代理的本机网关自身的流量在分配了 fakedns 地址后,再次进入 inbound 无法正确 sniffing 识别出来。

你期待看到的正常表现是怎样的?

局域网设备能够正常运行。

请附上你的配置

客户端配置:

{
dns": {
        "nameServer": [ 
            { 
                "address": {
                    "address": "FakeDNS"
                }
            },
            { 
                "address": {
                    "address": "1.1.1.1"
                }
            }
      ],
     "fakeDns": { 
            "pools": [ 
                {
                    "ipPool": "198.18.0.0/15",
                    "lruSize": 65535
                },
                {
                    "ipPool": "fc00::/18",
                    "lruSize": 65535
                }
            ]
        },
}
"inbounds": [
        {
            "protocol": "dokodemo-door", 
            "settings": {
                "networks": [
                    "TCP",
                    "UDP"
                ], 
                "followRedirect": true
            },
            "port": "1081",
            "listen": "0.0.0.0",
            "tag": "transparent",
            "sniffing": { 
                "enabled": true,
                "destOverride": [
                    "http",
                    "tls",
                    "fakedns+others"
                ],
                "metadataOnly": false
            },
            "streamSettings": { 
                "socketSettings": {
                    "tproxy": "tproxy"
                }
            }
        }
},
"outbounds": [
        {
            "protocol": "vmess",
            "settings": {
                "address": "your.domain", 
                "port": 443, 
                "uuid": "uuid-here"
            },
            "sendThrough": "0.0.0.0", 
            "tag": "out-vmess",
            "streamSettings": {
                "transport": "ws",
                "transportSettings": {
                    "path": "/AAA"
                }
            },
        {
            "protocol": "freedom",
            "tag": "direct-systemDNS",
            "domainStrategy": "AsIs"
        },
       {
            "protocol": "dns", 
            "tag": "dns-out"
        }
     ]
}

iptables 配置:

ip rule add fwmark 1 table 100
ip route add local 0.0.0.0/0 dev lo table 100

iptables -t mangle -N V2RAY
iptables -t mangle -A V2RAY -d 127.0.0.1/8 -p tcp -j RETURN
iptables -t mangle -A V2RAY -d 192.168.0.0/16 -p tcp -j RETURN
iptables -t mangle -A V2RAY -d 127.0.0.1/8 -p udp ! --dport 53 -j RETURN
iptables -t mangle -A V2RAY -d 192.168.0.0/16 -p udp ! --dport 53 -j RETURN
iptables -t mangle -A V2RAY -d 224.0.0.0/3 -j RETURN
iptables -t mangle -A V2RAY -p tcp -j TPROXY --on-port 1081 --tproxy-mark 1
iptables -t mangle -A V2RAY -p udp -j TPROXY --on-port 1081 --tproxy-mark 1
iptables -t mangle -A PREROUTING -j V2RAY

iptables -t mangle -N V2RAY_MASK
iptables -t mangle -A V2RAY_MASK -m owner --gid-owner 23333 -j RETURN
iptables -t mangle -A V2RAY_MASK -d 127.0.0.1/8 -p tcp -j RETURN
iptables -t mangle -A V2RAY_MASK -d 192.168.0.0/16 -p tcp -j RETURN
iptables -t mangle -A V2RAY_MASK -d 127.0.0.1/8 -p udp ! --dport 53 -j RETURN
iptables -t mangle -A V2RAY_MASK -d 192.168.0.0/16 -p udp ! --dport 53 -j RETURN
iptables -t mangle -A V2RAY_MASK -d 224.0.0.0/3 -j RETURN
iptables -t mangle -A V2RAY_MASK -j MARK --set-mark 1
iptables -t mangle -A OUTPUT -p tcp -j V2RAY_MASK
iptables -t mangle -A OUTPUT -p udp -j V2RAY_MASK

请附上出错时软件输出的错误日志

请附上访问日志

本机网关测试 curl google.com,等待后没有任何响应,日志如下:

2024/04/14 10:08:14 127.0.0.1:46749 accepted udp:127.0.0.1:53 [dns-out]
2024/04/14 10:08:14 192.168.116.129:47408 accepted udp:192.168.116.2:53 [dns-out]
2024/04/14 10:08:14 192.168.116.129:42382 accepted udp:192.168.116.2:53 [dns-out]
2024/04/14 10:08:14 192.168.116.129:52120 accepted tcp:198.18.0.1:80 [direct-systemDNS]

局域网设备配置 socks 代理后测试同样指令,日志如下:

2024/04/14 10:14:30 192.168.116.129:58775 accepted udp:192.168.116.2:53 [dns-out]
2024/04/14 10:14:33 192.168.244.2:54176 accepted //google.com:443 [out-vmess]
2024/04/14 10:14:34 192.168.244.2:54178 accepted //www.google.com:443 [out-vmess]

局域网设备在透明代理下其实和网关本机的测试效果是一样的,经过测试 删除 dns 中 fakedns 部分即可正常使用,但启用 fakedns 后好像无法正常 sniffing 探测原解析信息。

dyhkwong commented 3 months ago

不要使用 fakedns+others,因为 fakedns+others 从来就没有正常工作过。 1b0e046 使得 fakedns+othersfakedns 效果相同(但也不是预期的工作方式),但是 82c42fc 和 3c0aff7 又改坏了。 strings.HasPrefix(protocolString, p) || strings.HasSuffix(protocolString, p)strings.HasPrefix(protocolString, p) || strings.HasPrefix(p, protocolString) 可不是一回事。

nie11kun commented 3 months ago

不要使用 fakedns+others,因为 fakedns+others 从来就没有正常工作过1b0e046 使得 fakedns+othersfakedns 效果相同(但也不是预期的工作方式),但是 82c42fc3c0aff7 又改坏了。 strings.HasPrefix(protocolString, p) || strings.HasSuffix(protocolString, p)strings.HasPrefix(protocolString, p) || strings.HasPrefix(p, protocolString) 可不是一回事。

经过测试的确是这样的,修改 destOverride 中的 “fakedns+others” 为 “fakedns” 即可正常运行。