zfl9 / ipt2socks

将 iptables/nftables 传入的透明代理流量转为 socks5 流量的实用工具
GNU Affero General Public License v3.0
411 stars 94 forks source link

一直报failed to read data from socks5 server的错,网络不通 #7

Closed ow1wo closed 4 years ago

ow1wo commented 4 years ago

[udp_socks5_auth_read_cb] failed to read data from socks5 server: (4095) end of file 2019-11-12 08:02:20 ERR: [udp_socks5_auth_read_cb] failed to read data from socks5 server: (4095) end of file 2019-11-12 08:02:21 ERR: [udp_socks5_auth_read_cb] failed to read data from socks5 server: (4095) end of file 2019-11-12 08:02:23 ERR: [udp_socks5_auth_read_cb] failed to read data from socks5 server: (4095) end of file 2019-11-12 08:02:26 ERR: [udp_socks5_auth_read_cb] failed to read data from socks5 server: (4095) end of file 2019-11-12 08:02:30 ERR: [udp_socks5_auth_read_cb] failed to read data from socks5 server: (4095) end of file


配置环境: 网关上已运行v2ray,直接连v2ray可以通。之后想通过配置iptables把网段内所有流量用tproxy倒到v2ray上的任意门,由于v2ray udp有问题,所以想先把流量转成socks再进入v2ray任意门监听的端口。配置后出现上面的错误,网络不通。相关配置如下: iptables:

代理局域网设备

iptables -t mangle -N V2RAY iptables -t mangle -A V2RAY -d 127.0.0.1/32 -j RETURN iptables -t mangle -A V2RAY -d 224.0.0.0/4 -j RETURN iptables -t mangle -A V2RAY -d 255.255.255.255/32 -j RETURN iptables -t mangle -A V2RAY -d 10.1.0.0/16 -p tcp -j RETURN iptables -t mangle -A V2RAY -p udp -j TPROXY --on-port 60080 --tproxy-mark 1 iptables -t mangle -A V2RAY -p tcp -j TPROXY --on-port 60080 --tproxy-mark 1 iptables -t mangle -A PREROUTING -j V2RAY

代理网关本机

iptables -t mangle -N V2RAY_MASK iptables -t mangle -A V2RAY_MASK -d 224.0.0.0/4 -j RETURN iptables -t mangle -A V2RAY_MASK -d 255.255.255.255/32 -j RETURN iptables -t mangle -A V2RAY_MASK -d 10.1.0.0/16 -p tcp -j RETURN iptables -t mangle -A V2RAY_MASK -j RETURN -m mark --mark 0xff
iptables -t mangle -A V2RAY_MASK -p udp -j MARK --set-mark 1
iptables -t mangle -A V2RAY_MASK -p tcp -j MARK --set-mark 1
iptables -t mangle -A OUTPUT -j V2RAY_MASK


运行ipt2socks的参数: ipt2socks -s 127.0.0.1 -p 12345


v2ray的配置: { "log": { "loglevel": "warning" }, "inbounds": [{ "tag":"transparent", "port": 12345, "protocol": "dokodemo-door", "settings": { "network": "tcp,udp", "followRedirect": true }, "sniffing": { "enabled": true, "destOverride": [ "http", "tls" ] }, "streamSettings": { "sockopt": { "tproxy": "tproxy" // 透明代理使用 TPROXY 方式 } } }, { "port": 1080,
"listen": "0.0.0.0", "protocol": "socks", "sniffing": { "enabled": true, "destOverride": ["http", "tls"] }, "settings": { "auth": "noauth" } }], "outbounds": [{ "protocol": "vmess", "settings": { "vnext": [{


    }]
    },
    "streamSettings": 
    {
        "network": "ws",
        "security": "tls",
        "wsSettings": 
        {
        "path": "/v2ray"
        },
        "sockopt": 
    {
            "mark": 255
        }
    }
},
{
    "protocol": "freedom",
    "tag": "direct",
    "settings": {},
"streamSettings": 
{
        "sockopt": 
        {
            "mark": 255
        }
    }
},
{
    "protocol": "blackhole",
    "settings": {},
    "tag": "adblock"
}],
"routing": 
{
    "domainStrategy": "IPOnDemand",
    "rules": 
    [{
        "type": "field",
        "domain": 
        [

    ],
    "outboundTag": "direct"
},
{
        "type": "field",
        "ip": 
        [
    "geoip:cn",
    "geoip:private"
    ],
    "outboundTag": "direct"
},
{
        "type": "field",
    "domain": 
    [
    "geosite.dat:cn"
    ],
    "outboundTag": "direct"
},
{
        // Blocks major ads.
        "type": "field",
        "domain": 
        [
        "geosite:category-ads"
    ],
            "outboundTag": "blocked"
    }]
}

}

v2ray的log: 2019/11/12 08:42:42 [Warning] v2ray.com/core/transport/internet/tcp: failed to accepted raw connections > accept tcp [::]:12345: accept4: too many open files 2019/11/12 08:42:43 [Warning] v2ray.com/core/transport/internet/tcp: failed to accepted raw connections > accept tcp [::]:12345: accept4: too many open files 2019/11/12 08:42:43 [Warning] v2ray.com/core/transport/internet/tcp: failed to accepted raw connections > accept tcp [::]:12345: accept4: too many open files 2019/11/12 08:42:44 [Warning] v2ray.com/core/transport/internet/tcp: failed to accepted raw connections > accept tcp [::]:12345: accept4: too many open files 2019/11/12 08:42:44 [Warning] v2ray.com/core/transport/internet/tcp: failed to accepted raw

v2ray一直出现这种warning,整个网络不通。我对ipt2socks理解是数据包从其监听的60080端口进入,变成tcp socks包后再输出到启动参数配置的12345端口。是不是我理解错了?12345端口是v2ray的任意门端口,怎么会报failed to accepted呢?

zfl9 commented 4 years ago

ipt2socks 接受的是透明代理流量(从iptables过来的),然后发给 v2ray 的 socks5 监听端口。看名字就很清楚了,iptables-to-socks5。所以不要将 -s -p 指定为 v2ray 的透明代理端口,而是应该指向 v2ray 的 socks5 监听端口(启用tcp+udp)。

ow1wo commented 4 years ago

还是不行,尝试了各种配置,v2ray直接tproxy透明代理可以,前面套上这个ipt2socks就不通,两边报各种错误信息,摸不出规律。希望尝试成功的人能写个简易的步骤

zfl9 commented 4 years ago

...你把配置发上来(修改后的) @ow1wo

cattyhouse commented 4 years ago

还是不行,尝试了各种配置,v2ray直接tproxy透明代理可以,前面套上这个ipt2socks就不通,两边报各种错误信息,摸不出规律。希望尝试成功的人能写个简易的步骤

以你1楼给出的v2 配置情况,你应该运行

ipt2socks -s 127.0.0.1 -p 1080

而且v2 socks inbound 应该增加 udp... 默认只有 tcp的。