无法连接到Docker化的Tor代理 [英] Can't connect to dockerized tor proxy

查看:252
本文介绍了无法连接到Docker化的Tor代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Lubuntu上,我只能通过安装tor并连接到其袜子代理来使用tor,但是在带alpine的docker上似乎并不那么容易。
自从我离开了/ etc / tor / torrc以来,它只包含被注释掉的行。因此对于高山用户,我只使用了 torrc.sample 文件,该文件也只有注释掉的行。

On Lubuntu I was able to use tor just by installing it and then connecting to its socks proxy, but on docker with alpine it doesn't seem to be that easy. Since I left my /etc/tor/torrc the way it came, it only consisted of lines that were commented out. So for alpine I just used the torrc.sample file which also only had lines that were commented out.

这里是我的 Dockerfile

FROM alpine:latest
RUN apk update && apk upgrade && apk add tor curl && rm /var/cache/apk/* && cp /etc/tor/torrc.sample /etc/tor/torrc 
EXPOSE 9050
USER tor
CMD /usr/bin/tor -f /etc/tor/torrc

然后我刚刚运行:

$ sudo docker build -t tor .
$ sudo docker run --name tor -p 9050:9050 tor
$ curl -x socks5://localhost:9050 -k https://23.128.64.134/ip
curl: (7) Unable to receive initial SOCKS5 response.
$ curl -x socks4://localhost:9050 -k https://23.128.64.134/ip
curl: (7) Failed to receive SOCKS4 connect request ack.

但是您可以看到我无法连接。

But as you can see I'm not able to connect. Neither via socks4 nor via socks5.

我似乎无法弄清楚为什么这行不通。我已经尝试使用其他端口和主机名(127.0.0.1,而不是localhost),但是没有任何效果。

I can't seem to figure out why this isn't working. I've already tried using different ports and host names (127.0.0.1 instead of localhost), but nothing is working.

我在做什么错了?

编辑:

有趣的是,这似乎可行:

Interestingly though, this appears to work:

$ sudo docker exec -ti tor curl -x socks5://localhost:9050 -k https://23.128.64.134/ip
185.220.101.69

(185.220.101.69的确是Tor出口节点IP地址)

(185.220.101.69 is indeed a Tor exit node IP address)

那么这怎么了?为什么我不能从外面访问它?甚至 nmap 都报告它可以看到端口(在容器外部运行时):

So what could be wrong here? Why can't I access it from the outside? Even nmap is reporting that it can see the port (when run outside of the container):

9050/tcp open  tor-socks

Edit2:
我添加了 -v 标志以进行卷曲,并通过 echo Log info stdout>启用了更多详细的登录信息。 / etc / tor / torrc

I added the -v-flag to curl and enabled more verbose logging in tor via echo "Log info stdout" > /etc/tor/torrc.

当我从容器外部运行curl命令时,tor日志完全不变。 curl输出也没有显示任何帮助:

The tor log doesn't change at all when I run the curl command from outside the container. The curl output also doesn't show anything helpful:

$ curl -v -x socks5://localhost:9050 -k https://23.128.64.134/ip
*   Trying ::1:9050...
* TCP_NODELAY set
* SOCKS5 communication to 23.128.64.134:443
* Unable to receive initial SOCKS5 response.
* Closing connection 0
curl: (7) Unable to receive initial SOCKS5 response.

$ curl -v -x socks5://127.0.0.1:9050 -k https://23.128.64.134/ip
*   Trying 127.0.0.1:9050...
* TCP_NODELAY set
* SOCKS5 communication to 23.128.64.134:443
* Unable to receive initial SOCKS5 response.
* Closing connection 0
curl: (7) Unable to receive initial SOCKS5 response.


推荐答案

我设法弄清楚了。问题在于,Tor默认情况下不会绑定到所有接口(例如 0.0.0.0 ),而该接口在Docker上无法很好地发挥作用。

I managed to figure it out. The problem is that Tor by default doesn't bind to all interfaces (as in 0.0.0.0) which doesn't play nicely with Docker.

可以通过在 / etc中添加 SocksPort 0.0.0.0:9050 来解决此问题。 / tor / torrc

This can be fixed by adding SocksPort 0.0.0.0:9050 to the /etc/tor/torrc.

因此解决方案是:

FROM alpine:latest
RUN apk update && apk upgrade && \
    apk add tor curl && \
    rm /var/cache/apk/* && \
    cp /etc/tor/torrc.sample /etc/tor/torrc && \
    echo "SocksPort 0.0.0.0:9050" > /etc/tor/torrc
EXPOSE 9050
USER tor
CMD /usr/bin/tor -f /etc/tor/torrc

然后一切都会按预期进行:

Then everything works as expected:

$ sudo docker build -t tor .
$ sudo docker run --name tor -p 9050:9050 tor
$ curl -x socks5://localhost:9050 https://ifconfig.io/ip
190.216.2.136

这篇关于无法连接到Docker化的Tor代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆