2018-05-03 18:12:30 +08:00
< p align = "center" >
< img width = "300px" src = "https://upload.wikimedia.org/wikipedia/commons/8/8f/Tor_project_logo_hq.png" >
< / p >
2018-07-22 14:17:09 +08:00
# Tor-socks-proxy
2017-01-10 09:17:07 +08:00
2018-07-13 00:50:28 +08:00

2018-07-13 01:00:45 +08:00
[](https://travis-ci.com/PeterDaveHello/tor-socks-proxy)
2018-07-13 01:01:56 +08:00
[](https://hub.docker.com/r/peterdavehello/tor-socks-proxy/)
[](https://microbadger.com/images/peterdavehello/tor-socks-proxy/)
[](https://hub.docker.com/r/peterdavehello/tor-socks-proxy/tags/)
2018-02-13 01:46:10 +08:00
2018-07-22 14:13:16 +08:00
[](https://hub.docker.com/r/peterdavehello/tor-socks-proxy/)
2018-05-03 18:19:59 +08:00
The super easy way to setup a [Tor ](https://www.torproject.org ) [SOCKS5 ](https://en.wikipedia.org/wiki/SOCKS#SOCKS5 ) [proxy server ](https://en.wikipedia.org/wiki/Proxy_server ) inside a [Docker ](https://en.wikipedia.org/wiki/Docker_(software )) [container ](https://en.wikipedia.org/wiki/Container_(virtualization )) without relay/exit feature.
2017-01-10 09:17:07 +08:00
2018-07-22 14:17:09 +08:00
## Usage
2017-01-10 09:17:07 +08:00
1. Setup the proxy server at the **first time**
2018-07-14 21:59:02 +08:00
2017-01-10 09:17:07 +08:00
```sh
2019-12-07 22:21:44 +08:00
$ docker run -d --restart=always --name tor-socks-proxy -p 127.0.0.1:9150:9150 peterdavehello/tor-socks-proxy:latest
2017-01-10 09:17:07 +08:00
```
2019-12-07 22:21:44 +08:00
- With parameter `--restart=always` the container will always start on daemon startup, which means it'll automatically start after system reboot.
2017-11-06 05:12:30 +08:00
- Use `127.0.0.1` to limit the connections from localhost, do not change it unless you know you're going to expose it to a local network or to the Internet.
2018-02-24 03:15:27 +08:00
- Change to first `9150` to any valid and free port you want, please note that port `9050` /`9150` may already taken if you are also running other Tor client, like TorBrowser.
2017-11-06 05:12:30 +08:00
- Do not touch the second `9150` as it's the port inside the docker container unless you're going to change the port in Dockerfile.
2019-12-07 22:21:44 +08:00
If you already setup the instance before *(not the first time)* but it's in stopped state, you can just start it instead of creating a new one:
2018-07-14 21:59:02 +08:00
```sh
2019-12-07 20:19:56 +08:00
$ docker start tor-socks-proxy
2017-01-10 09:17:07 +08:00
```
2017-11-06 05:12:30 +08:00
2. Make sure it's running, it'll take a short time to bootstrap
2018-07-14 21:59:02 +08:00
2018-07-22 14:17:09 +08:00
```sh
2019-12-07 20:19:56 +08:00
$ docker logs tor-socks-proxy
2017-01-10 09:17:07 +08:00
.
.
.
Jan 10 01:06:59.000 [notice] Bootstrapped 85%: Finishing handshake with first hop
Jan 10 01:07:00.000 [notice] Bootstrapped 90%: Establishing a Tor circuit
Jan 10 01:07:02.000 [notice] Tor has successfully opened a circuit. Looks like client functionality is working.
Jan 10 01:07:02.000 [notice] Bootstrapped 100%: Done
```
2017-11-06 05:12:30 +08:00
3. Configure your client to use it, target on `127.0.0.1` port `9150` (Or the other port you setup in step 1)
2017-01-10 09:17:07 +08:00
2018-02-24 03:15:27 +08:00
Take `curl` as an example, checkout what's your IP address via Tor network:
2018-07-14 21:59:02 +08:00
2017-01-10 09:33:41 +08:00
```sh
2019-10-28 12:03:46 +08:00
$ curl --socks5-hostname 127.0.0.1:9150 https://ipinfo.tw/ip
2019-10-28 10:58:00 +08:00
$ curl --socks5-hostname 127.0.0.1:9150 https://ipinfo.io/ip
$ curl --socks5-hostname 127.0.0.1:9150 https://icanhazip.com
$ curl --socks5-hostname 127.0.0.1:9150 https://ipecho.net/plain
2017-01-10 09:33:41 +08:00
```
2018-02-18 01:04:32 +08:00
Take `ssh` and `nc` as an example, connect to a host via Tor:
2018-07-14 21:59:02 +08:00
2017-01-10 09:33:41 +08:00
```sh
$ ssh -o ProxyCommand='nc -x 127.0.0.1:9150 %h %p' target.hostname.blah
```
2017-01-10 09:17:07 +08:00
4. After using it, you can turn it off
2018-07-14 21:59:02 +08:00
2017-01-10 09:17:07 +08:00
```sh
2019-12-07 20:19:56 +08:00
$ docker stop tor-socks-proxy
2017-01-10 09:17:07 +08:00
```
2017-11-06 05:19:59 +08:00
2018-07-22 14:17:09 +08:00
## IP renewal
2017-11-06 05:19:16 +08:00
2019-03-29 18:01:01 +08:00
- Tor changes circuit automatically every 10 minutes by default, which usually bring you the new IP address, it's affected by `MaxCircuitDirtiness` config, you can override it with your own `torrc` . See the official [manual ](https://www.torproject.org/docs/tor-manual.html.en ) for more details.
- To manually renew the IP that Tor gives you, simply restart your docker container to open a new circuit:
2018-07-14 21:59:02 +08:00
2017-11-06 05:19:16 +08:00
```sh
2019-12-07 20:19:56 +08:00
$ docker restart tor-socks-proxy
2017-11-06 05:19:16 +08:00
```
2019-03-29 18:01:01 +08:00
Just note that all the connections will be terminated and need to be reestablished.
2017-11-06 05:19:16 +08:00
2017-11-06 05:19:59 +08:00
## Note
2017-11-06 05:12:30 +08:00
2018-06-30 02:45:42 +08:00
**For the Tor project sustainability, I strongly encourage you to help [setup Tor bridge/exit nodes ](https://trac.torproject.org/projects/tor/wiki/TorRelayGuide )([**script** ](https://github.com/PeterDaveHello/ubuntu-tor-simply-setup )) and [donate ](https://donate.torproject.org/ ) money to the Tor project *(Not this proxy project)* when you have the ability/capacity!**