Linux 如何使用不同的退出 IP 一次运行多个 Tor 进程?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14321214/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to run multiple Tor processes at once with different exit IPs?
提问by B.Mr.W.
I am brand new to Tor and I feel like multiple Tors should be considered. The multiple tors I mentioned here are not only multiple instances, but also using different proxy ports for each, like what has been done here http://www.howtoforge.com/ultimate-security-proxy-with-tor)
我是 Tor 的新手,我觉得应该考虑多个 Tor。我在这里提到的多个 Tor 不仅是多个实例,而且每个实例都使用不同的代理端口,就像这里所做的 http://www.howtoforge.com/ultimate-security-proxy-with-tor)
I am trying to get started with 4 Tors. However, the tutorial applies only to Arch Linux and I am using a headless EC2 ubuntu 64bits. It is really a pain going through the differences between Arch and Ubuntu. And here I am wondering is there anyone could offer some help to implement my idea simplicitly.
我正在尝试开始使用 4 Tors。但是,本教程仅适用于 Arch Linux,我使用的是无头 EC2 ubuntu 64 位。经历 Arch 和 Ubuntu 之间的差异真的很痛苦。在这里,我想知道是否有人可以提供一些帮助来简单地实现我的想法。
Four Tors running at the same time each with an individual port, privoxy or polipo or whatever are ok once it works. Like: 8118 <- Privoxy <- TOR <- 9050 8129 <- Privoxy <- TOR <- 9150 8230 <- Privoxy <- TOR <- 9250 8321 <- Privoxy <- TOR <- 9350
In this way, if I try to return the ip of 127.0.0.1:8118, 8129, 8230 and 8321, they should return four different ips, which indicates there are four different Tors running at the same time. Then, a few minutes later, check again, all four of them should have a new ips again.
四个 Tors 同时运行,每个 Tors 都有一个单独的端口,privoxy 或 polipo 或者一旦它工作就可以了。像:8118 <- Privoxy <- TOR <- 9050 8129 <- Privoxy <- TOR <- 9150 8230 <- Privoxy <- TOR <- 9250 8321 <- Privoxy <- TOR <- 9350
这样,如果我尝试返回 127.0.0.1:8118、8129、8230 和 8321 的 ip,它们应该返回四个不同的 ip,这表明有四个不同的 Tors 同时运行。然后,几分钟后,再次检查,他们四个应该都有一个新的ips。
I know my simple 'dream' could come true in many ways, however... I am not only new to Tor, but even also to bash and python... That is why I come here and see whether some of you could light me up.
我知道我的简单“梦想”可以在很多方面实现,但是……我不仅是 Tor 的新手,甚至还对 bash 和 python 不熟悉……这就是为什么我来这里看看你们中的一些人是否可以点亮我起来。
These links might be useful:
这些链接可能有用:
http://blog.databigbang.com/distributed-scraping-with-multiple-tor-circuits/https://www.torservers.net/wiki/setup/server#multiple_tor_processesBest,
http://blog.databigbang.com/distributed-scraping-with-multiple-tor-circuits/ https://www.torservers.net/wiki/setup/server#multiple_tor_processes最好,
btw, if I run
$ ps -A | grep 'tor'
i have several instances there, however with "?" under the tty column, what does that mean since I know tty means terminals?
顺便说一句,如果我运行
$ ps -A | grep 'tor'
我有几个实例,但是“?” 在 tty 列下,这是什么意思,因为我知道 tty 表示终端?
采纳答案by zkilnbqi
Create four torrc files, say /etc/tor/torrc.1
to .4
.
创建四个 torrc 文件,比如/etc/tor/torrc.1
to .4
.
In each file, edit the lines:
在每个文件中,编辑以下行:
SocksPort 9050
ControlPort 9051
DataDirectory /var/lib/tor
to use different resources for each torrc
file, e.g. for for torrc.1
:
为每个torrc
文件使用不同的资源,例如 for torrc.1
:
SocksPort 9060
ControlPort 9061
DataDirectory /var/lib/tor1
for torrc.2
,
对于torrc.2
,
SocksPort 9062
ControlPort 9063
DataDirectory /var/lib/tor2
and so on.
等等。
A configuration file containing only the above lines will work: you can delete every other line from the default template if you feel like it.
仅包含上述行的配置文件将起作用:如果您愿意,可以从默认模板中删除所有其他行。
DataDirectory
can also be relative to the current directory where tor
is launched, e.g.:
DataDirectory
也可以相对于启动的当前目录tor
,例如:
DataDirectory d1
Then start tor like this:
然后像这样启动tor:
tor -f /etc/tor/torrc.1
tor -f /etc/tor/torrc.2
and so on for the other two files.
其他两个文件依此类推。
This will create four different Socks5 servers on the four ports. Each one will open a different circuit, which is what you want.
这将在四个端口上创建四个不同的 Socks5 服务器。每个人都会打开不同的电路,这就是您想要的。
回答by adrelanos
Chaining Tor is recommended against. You may get worse anonymity, not better anonymity.
建议使用链接 Tor 来对抗. 你可能会得到更糟糕的匿名,而不是更好的匿名。
Doing so produces undefined and potentially unsafe behavior. In theory, however, you can get six hops instead of three, but it is not guaranteed that you'll get three different hops - you could end up with the same hops, maybe in reverse or mixed order. It is not clear if this is safe. It has never been discussed.
You can ?choose an entry/exit point, but you get the best security that Tor can provide when you leave the route selection to Tor; overriding the entry / exit nodes can mess up your anonymity in ways we don't understand. Therefore Tor over Tor usage is highly discouraged.
这样做会产生未定义且可能不安全的行为。然而,从理论上讲,您可以获得 6 跳而不是 3 跳,但不能保证您会得到 3 次不同的跳 - 您最终可能会得到相同的跳,可能是相反的或混合的顺序。目前尚不清楚这是否安全。它从未被讨论过。
您可以选择一个入口/出口点,但是当您将路由选择留给 Tor 时,您将获得 Tor 所能提供的最佳安全性;覆盖进入/退出节点可能会以我们不理解的方式破坏您的匿名性。因此,强烈建议不要使用 Tor 过度使用 Tor。
You should only mess with Tor's routing algorithm, if you are more clever than the Tor developers.
如果您比 Tor 开发人员更聪明,您应该只使用 Tor 的路由算法。
The use of privoxy / polipo has been deprecated by The Tor Project long time ago. You are recommendedto only use Tor Browser. Only Tor Browser gives you an unified web fingerprint and you won't stand out.
The Tor Project 很久以前就弃用了 privoxy / polipo。您建议只使用Tor浏览器。只有 Tor 浏览器为您提供统一的网络指纹,您不会脱颖而出。
Since Tor version 0.2.3, different Socks,- Dns-, or TransPorts go through different circuits, therefore preventing identity correlation. The term for this is stream isolation. Do get this, you can add to torrc...
从 Tor 版本 0.2.3 开始,不同的 Socks、-Dns- 或 TransPorts 通过不同的电路,因此阻止了身份关联。这个术语是流隔离。得到这个,你可以添加到torrc ...
SocksPort 9050
SocksPort 9052
SocksPort 9053
SocksPort 9054
#...
...and they will all go thought different circuits.
...他们都会去想不同的电路。
When you are using Tor Browser, you can also use Tor Button's new identity feature. Click on Tor Button (the green onion) and choose new identity. This will reset all browser states and change Tor's circuit.
当您使用 Tor 浏览器时,您还可以使用 Tor Button 的新身份功能。单击 Tor 按钮(葱)并选择新身份。这将重置所有浏览器状态并更改 Tor 的电路。
Note, when using stream isolation, going through different circuits does not guarantee getting different Tor exit nodes. Sometimes Tor will only use a different entry guard or middle relay. This is normal.
请注意,使用流隔离时,通过不同的电路并不能保证获得不同的 Tor 出口节点。有时 Tor 只会使用不同的入口守卫或中间中继。这是正常的。
回答by adrelanos
Make a tor configuration directory: $> mkdir -p ~/configuration_files/tor
$> config=~/configuration_files/tor
$> cd "${config}"
Copy the /etc/tor/torrc
to the configuration directory and make as many copies as you need: E.g. 10 printf "torrc_%0.2s\n" {1..10} | xargs -I {} /bin/cp /etc/tor/torrc "${config}{}"
制作一个tor配置目录:$> mkdir -p ~/configuration_files/tor
$> config=~/configuration_files/tor
$> cd "${config}"
将其复制/etc/tor/torrc
到配置目录并根据需要制作尽可能多的副本:例如10 printf "torrc_%0.2s\n" {1..10} | xargs -I {} /bin/cp /etc/tor/torrc "${config}{}"
Copy the /etc/torsocks.conf
to the configuration directory and make as many copies as you need: e.g. same as above 10printf "torsocks_%0.2s.conf\n" {1..10} | xargs -I {} /bin/cp /etc/torsocks.conf "${config}/{}"
将其复制/etc/torsocks.conf
到配置目录并根据需要制作尽可能多的副本:例如与上述 10 相同printf "torsocks_%0.2s.conf\n" {1..10} | xargs -I {} /bin/cp /etc/torsocks.conf "${config}/{}"
Make new data directories and fix ownership/permissions: $> sudo mkdir /var/lib/tor{1..10}
创建新的数据目录并修复所有权/权限: $> sudo mkdir /var/lib/tor{1..10}
Edit the configuration files to have non colliding corresponding port numbers:
编辑配置文件以具有不冲突的对应端口号:
for a in {1..10}; do
sed -i "s/^#SocksPort 9050.*/SocksPort $((9050+${i}))/;s|^#DataDirectory /var/lib/tor|DataDirectory /var/lib/tor${i}|" torrc_${i}
sed -i "s/server_port = 9050/server_port = $((9050+${i}))/" torsocks_${i}.conf
sudo chmod -R --reference /var/lib/tor /var/lib/tor${i}
sudo chown -R CHANGETHIS:CHANGETHIS /var/lib/tor${i}
done
Note: Changing the CHANGETHIS to the user/group of the user who plans to use it.
注意:将 CHANGETHIS 更改为计划使用它的用户的用户/组。
After that its easy to get going, you start up the individual instances of tor using the corresponding configuration file
E.g. /usr/bin/tor -f "${config}/torrc_3"
之后就很容易上手了,你可以使用相应的配置文件来启动 Tor 的各个实例,例如 /usr/bin/tor -f "${config}/torrc_3"
To use it all you need to do is export the variable TORSOCKS_CONF_FILE to point to the corresponding torsocks.conf
file:
E.g. $> export TORSOCKS_CONF_FILE="${config}/torsocks_3.conf"
要使用它,您需要做的就是导出变量 TORSOCKS_CONF_FILE 以指向相应的torsocks.conf
文件:
例如$> export TORSOCKS_CONF_FILE="${config}/torsocks_3.conf"
Next you can torify / torsocks any application from that particular shell and it will use the torsocks_3.conf proxy.
Try: $> torify bash
$> curl www.ipmango.com/api/myip
接下来,您可以 torify / torsocks 来自该特定 shell 的任何应用程序,它将使用 torsocks_3.conf 代理。
尝试:$> torify bash
$> curl www.ipmango.com/api/myip
To change to another proxy simply start up the corresponding tor using its torrc file and export the TORSOCKS_CONF_FILE variable to point to the new configuration.
要更改为另一个代理,只需使用其 torrc 文件启动相应的 Tor 并导出 TORSOCKS_CONF_FILE 变量以指向新配置。
Here is a simple alias that does the job, after you've set it up as above and you have roxterm installed. It will check netstat
to see if the proxy is up already and if not it will start it up in a separate shell window.
这是一个简单的别名,在您按照上述方式设置并安装了 roxterm 之后,它可以完成这项工作。它将检查netstat
代理是否已经启动,如果没有,它将在单独的 shell 窗口中启动它。
alias prox='_(){ proxy=${1:-1}; config_base="~/configuration_files/tor"; port=$((9050+${proxy})); netstat -an | { ! grep -q "127.0.0.1:${port}"; } && roxterm -e bash -c "/usr/bin/tor -f \"${config_base}/torrc_${proxy}\"; bash"; export TORSOCKS_CONF_FILE="${config_base}/torsocks_${proxy}.conf"; }; _'
alias prox='_(){ proxy=${1:-1}; config_base="~/configuration_files/tor"; port=$((9050+${proxy})); netstat -an | { ! grep -q "127.0.0.1:${port}"; } && roxterm -e bash -c "/usr/bin/tor -f \"${config_base}/torrc_${proxy}\"; bash"; export TORSOCKS_CONF_FILE="${config_base}/torsocks_${proxy}.conf"; }; _'
To use it:
要使用它:
$> prox 4
$> torify bash
回答by momen
I tried the torrc.1 ,torrc.2 etc...but it didn't work.
我尝试了 torrc.1 、torrc.2 等......但它没有用。
However this one worked:
然而,这个工作:
- Stop the tor process by :
/etc/init.d/tor stop
- Open
gedit /etc/tor/torrc
(If you are not root put sudo before it to access as root) - Search for
SocksPort 9050
- Now put whatever ports you want to be as stream ports (SocksPort 9060 ,SocksPort 9070,SocksPort 9080 ....etc.)
- Search for ControlPort 9051
- Now put whatever ports you want to be as stream ports (ControlPort 9061 ,ControlPort 9071,ControlPort 9081 ....etc.) NOTICE THAT CONTROL PORT IS ALWAYS SOCKSPORT+1
- Start the tor process again :
/etc/init.d/tor start
- Check the tor status
/etc/init.d/tor status
- 通过以下方式停止 Tor 进程:
/etc/init.d/tor stop
- 打开
gedit /etc/tor/torrc
(如果您不是 root,则在它之前放置 sudo 以作为 root 访问) - 搜索
SocksPort 9050
- 现在把你想成为的任何端口作为流端口(SocksPort 9060、SocksPort 9070、SocksPort 9080 ....等)
- 搜索 ControlPort 9051
- 现在把你想要的任何端口作为流端口(ControlPort 9061 ,ControlPort 9071,ControlPort 9081 ....etc.)注意控制端口总是 SOCKSPORT+1
- 再次启动 tor 进程:
/etc/init.d/tor start
- 查看tor状态
/etc/init.d/tor status
it should show something like that:
它应该显示如下内容:
tor.service - Anonymizing overlay network for TCP
Loaded: loaded (/lib/systemd/system/tor.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2016-05-13 22:18:21 GST; 1s ago
Process: 10259 ExecReload=/bin/kill -HUP ${MAINPID} (code=exited, status=0/SUCCESS)
Process: 10319 ExecStartPre=/usr/bin/tor --defaults-torrc /usr/share/tor/tor-service-defaults-torrc -f /etc/tor/torrc --RunAsDaemon 0 --verify-config (code=exited, status=0/SUCCESS)
Process: 10317 ExecStartPre=/usr/bin/install -Z -m 02750 -o debian-tor -g debian-tor -d /var/run/tor (code=exited, status=0/SUCCESS)
Main PID: 10322 (tor)
CGroup: /system.slice/tor.service
└─10322 /usr/bin/tor --defaults-torrc /usr/share/tor/tor-service-defaults-torrc -f /etc/tor/torrc --RunAsDaemon 0
May 13 22:18:20 momen-Lenovo tor[10322]: May 13 22:18:20.860 [notice] Tor v0.2.6.10 (git-71459b2fe953a1c0) running on Linux with Li... 1.2.8.
May 13 22:18:20 momen-Lenovo tor[10322]: May 13 22:18:20.860 [notice] Tor can't help you if you use it wrong! Learn how to be safe ...warning
May 13 22:18:20 momen-Lenovo tor[10322]: May 13 22:18:20.860 [notice] Read configuration file "/usr/share/tor/tor-service-defaults-torrc".
May 13 22:18:20 momen-Lenovo tor[10322]: May 13 22:18:20.860 [notice] Read configuration file "/etc/tor/torrc".
May 13 22:18:20 momen-Lenovo tor[10322]: May 13 22:18:20.863 [notice] Opening Socks listener on 127.0.0.1:9050
May 13 22:18:20 momen-Lenovo tor[10322]: May 13 22:18:20.863 [notice] Opening Socks listener on 127.0.0.1:9060
May 13 22:18:20 momen-Lenovo tor[10322]: May 13 22:18:20.863 [notice] Opening Control listener on 127.0.0.1:9051
May 13 22:18:20 momen-Lenovo tor[10322]: May 13 22:18:20.863 [notice] Opening Control listener on 127.0.0.1:9061
May 13 22:18:20 momen-Lenovo tor[10322]: May 13 22:18:20.863 [notice] Opening Control listener on /var/run/tor/control
May 13 22:18:21 momen-Lenovo systemd[1]: Started Anonymizing overlay network for TCP.
Hint: Some lines were ellipsized, use -l to show in full.
提示:有些行被省略,使用 -l 显示完整。