缘起:搜索某个配置,找到了linux.do,发现社区氛围不错,还需要邀请才能注册,试着在群里问了一下,一位佬就送了我一个邀请码,在此表示感谢。并以本文回馈社区。
正文:【serv00】接入tor网络,配合v2ray无缝访问tor网络
正常的freebsd安装tor,就一行指令 pkg install tor
,
然而咱们的机器没有root权限,所以无法安装。
经过我的尝试,通过以下方法,就可以实现serv00使用tor。
一、下载tor安装包:
tor https://pkg.freebsd.org/FreeBSD:14:amd64/latest/All/tor-0.4.8.12.pkg
下面三个是依赖,如果提示跑不起来,再去https://freebsd.pkgs.org/14/freebsd-amd64/tor-0.4.8.12.pkg.html这个地方按文件名搜索后,找到pkg下载,将相应的bin放入到tor一块。
libevent-2.1.12.pkg
liblz4-1.10.0,1.pkg
zstd-1.5.6.pkg
二、解压:
使用winrar,找到tor-0.4.8.12.pkg,并将tor-0.4.8.12\usr\local\bin目录下载文件解压到bin目录下面,再将tor-0.4.8.12\usr\local\share\tor目录下载的geoip和geoip6也解压到bin目录下面。
三、写配置:
在bin目录,新建一个torrc的文件,内容如下:
HardwareAccel 1
##GEOIP文件,排除节点使用
GeoIPFile /home/your_serv00_vhost/tor/bin/geoip
GeoIPv6File /home/your_serv00_vhost/tor/bin/geoip6
##排除一些节点
ExcludeNodes {cn},{hk},{mo},{kp},{ir},{sy},{pk},{cu},{vn}
ExcludeExitNodes {cn},{hk},{mo},{kp},{ir},{sy},{pk},{cu},{vn}
StrictNodes 1
##如果需要dns服务,就开一个udp的端口
#DNSPort 0.0.0.0:8853
##socks服务,开一个tcp的端口
SocksPort 127.0.0.1:55553
#数据目录,需要在serv00上创建该目录。
DataDirectory /home/your_serv00_vhost/tor/bin
Log notice stdout
#Log notice file /var/log/tor/notices.log
四,上传至serv00主机:
跑到serv00主机上,创建tor/bin的目录,pwd之
后显示路径为/home/your_serv00_vhost/tor/bin
并且使用chmod +x
将除torrc、geoip、geoip6外的文件,都加上可执行的权限。
五、执行tor
/home/your_serv00_vhost/tor/bin/tor -f /home/your_serv00_vhost/tor/bin/torrc
执行之后,服务器上的日志回显,看时间,执行有点慢。
Sep 03 11:30:53.461 [notice] Tor 0.4.8.12 running on FreeBSD with Libevent 2.1.12-stable, OpenSSL 3.0.13, Zlib 1.3.1, Liblzma 5.4.5, Libzstd 1.5.6 and BSD 1400097 as libc.
Sep 03 11:30:53.461 [notice] Tor can't help you if you use it wrong! Learn how to be safe at https://support.torproject.org/faq/staying-anonymous/
Sep 03 11:30:53.462 [notice] Read configuration file "/home/your_serv00_vhost/tor/bin/torrc".
Sep 03 11:30:53.532 [warn] You have asked to exclude certain relays from all positions in your circuits. Expect hidden services and other Tor features to be broken in unpredictable ways.
Sep 03 11:30:53.534 [notice] Opening Socks listener on 127.0.0.1:55553
Sep 03 11:30:53.534 [notice] Opened Socks listener connection (ready) on 127.0.0.1:55553
Sep 03 11:30:53.000 [notice] Parsing GEOIP IPv4 file /home/your_serv00_vhost/tor/bin/geoip.
Sep 03 11:31:18.000 [notice] Parsing GEOIP IPv6 file /home/your_serv00_vhost/tor/bin/geoip6.
Sep 03 11:31:57.000 [notice] Bootstrapped 0% (starting): Starting
Sep 03 11:33:59.000 [notice] Starting with guard context "default"
Sep 03 11:34:04.000 [notice] Bootstrapped 5% (conn): Connecting to a relay
Sep 03 11:34:04.000 [notice] Bootstrapped 10% (conn_done): Connected to a relay
Sep 03 11:34:05.000 [notice] Bootstrapped 14% (handshake): Handshaking with a relay
Sep 03 11:34:06.000 [notice] Bootstrapped 15% (handshake_done): Handshake with a relay done
Sep 03 11:34:06.000 [notice] Bootstrapped 75% (enough_dirinfo): Loaded enough directory info to build circuits
Sep 03 11:34:09.000 [notice] Bootstrapped 80% (ap_conn): Connecting to a relay to build circuits
Sep 03 11:34:26.000 [notice] Bootstrapped 85% (ap_conn_done): Connected to a relay to build circuits
Sep 03 11:34:29.000 [notice] Bootstrapped 89% (ap_handshake): Finishing handshake with a relay to build circuits
Sep 03 11:34:33.000 [notice] Bootstrapped 90% (ap_handshake_done): Handshake finished with a relay to build circuits
Sep 03 11:34:33.000 [notice] Bootstrapped 95% (circuit_create): Establishing a Tor circuit
Sep 03 11:35:44.000 [notice] No circuits are opened. Relaxed timeout for circuit 2 (a Unlinked conflux circuit 3-hop circuit in state doing handshakes with channel state open) to 60000ms. However, it appears the circuit has timed out anyway.
Sep 03 11:35:47.000 [notice] Bootstrapped 100% (done): Done
六、执行测试:
curl https://check.torproject.org/api/ip
{"IsTor":false,"IP":"85.194.244.91"}
curl --socks5-hostname 127.0.0.1:55553 https://check.torproject.org/api/ip
{"IsTor":true,"IP":"192.42.116.187"}
七、v2ray服务端配置:
主要是在outbounds中,加入"tag": "tor-outbound"
。
以及在routing中,加入"outboundTag": "tor-outbound"
。
{
"log": {
"loglevel": "none"
},
"inbounds": [
],
"dns": {
"servers": [
"https+local://1.1.1.1/dns-query",
"https+local://8.8.8.8/dns-query"
]
},
"outbounds": [
{
"tag": "tor-outbound",
"protocol": "socks",
"settings": {
"servers": [
{
"address": "127.0.0.1",
"port": 55553
}
]
}
}
],
"routing": {
"domainStrategy": "IPIfNonMatch",
"rules": [
{
"type": "field",
"domain": [
"regexp:\\.onion$"
],
"outboundTag": "tor-outbound"
}
]
}
}
最后,打完收工。
当然,其它玩法也不是没有,自己挖吧……
PS:
本文未提及保活的内容,相关已经有好多佬写过……请自行抄作业。
我说一下我的做法(也是抄来的):
1、crontab加入一个任务bh2.js,每xx分钟检查bh1.js是否存在。
exec("pgrep -laf bh1.js
,存在就结束,不存在就node bh1.js
2、bh1.js,每xx秒检查一下v2ray和tor
exec("pgrep -laf 'v2ray|tor'"
,存在就结束,不存在就运行相应的程序。
另外,如果tor不与v2ray结合,直接单用也是可以的。
那就是想要多少IP节点就有多少IP节点了。具体配置,自己调整即可。
比如: [