written in front
I am working on some mysterious projects recently, and I need to use the proxy access mode of http->socks5. There are a lot of configuration instructions on the Internet, either the donkey’s head is wrong, or I haven’t explained things clearly for a long time, or I just copy and paste, so I write this article .
Article directory
Configure Tor
It is very simple to configure Tor on centos. It can be installed directly through yum. Before installation, it should be noted that Tor no longer recommends using its warehouse for CentoOS, but recommends using the epel warehouse, so first install the epel warehouse, and then Just install Tor (the following commands use root privileges without special declaration)
yum install epel-release
yum install tor
After installation, you need to modify the configuration file of Tor, so
vim /etc/tor/torrc
After opening, there is only one place we need to change. Find the following line and open the comment. The default port of Tor on Linux is 9050. If necessary, you can change the port by yourself.
SOCKSPort 9050
Then you can start the Tor service
service tor restart
systemctl restart tor
Then we can test whether the configuration is successful (no root privileges required)
curl --socks5-hostname localhost:9050 https://check.torproject.org
If the shell returns the following figure, it is successfully configured
possible problems
After configuring Tor, although the test check.torproject.org
is successful, if you use curl
more to test some mysterious websites, you will find such an error: Can't complete SOCKS5 connection to 0.0.0.0:0.
I have studied this problem for a long time and tried a lot There are two ways to locate the problem, and finally found that there are two possibilities:
- If there is a 504 error when using http access, then the remote server is not open. In this case, you can only wait for the other party's website server to open before accessing
- Because we are using
curl
the-hostname
parameters, the DNS resolution is in the remote Tor. It may be that the DNS resolution on Tor is wrong. In this case, the problem lies in the version of Tor. Use the command toyum list installed
check the version of the installation package. We You only need to care about the versions of the three installation packages:epel
the warehouse,tor
andtorsocks
because sometimesyum
the installation software is not necessarily a newer version, which may cause errors. The warehouses on my two serversepel
are all7-11
versions, but using them One of the installedTor
versions is0.3.5
the other , and the version of0.2.9
Tor's dependent package is also a new version and an old version, which causes one of the two servers to resolve DNS normally, while the other will report the above error, so it needs to be manually updatedtorsocks
Tor to the latest version
Currently using Tor 0.3.5 can resolve DNS normally, and the problem will be solved after updating the version. If you happen to be unable to install a newer version of Tor in your warehouse, you can click here to install it offline . Extraction code: b7bk
Configure Polipo
The configuration of Polipo is a bit more complicated. The tutorials on the Internet are mixed, and I am overwhelmed, so I slowly figured out a better way to go. First, open this website: download address, select the file in the picture circle above to download, of course, you can also
download it
. Direct use wget
(no root permission required)
wget https://copr-be.cloud.fedoraproject.org/results/jasonbrooks/polipo/epel-7-x86_64/polipo-1.1.1-2.fc22/polipo-1.1.1-2.el7.centos.x86_64.rpm
Then use yum
to install
yum install polipo-1.1.1-2.el7.centos.x86_64.rpm
Almost all the tutorials on the Internet download the source code from github and compile and configure it yourself. make
It takes a long time to complete a lot of config
files. I don’t know why each person writes one method. Isn’t it good to go directly to the installation package?
Then we can enter Polipo's default configuration file location
vim /etc/polipo/config
There are a lot of comments inside
. Don't panic, we just need to find the following lines to open the comments
socksParentProxy = "localhost:9050" # 因为我们要与Tor一起使用
socksProxyType = socks5 # 这里Polipo提供了把他接管的http送到socks5的方法
diskCacheRoot = "" # 这一行跟上两行不挨在一起,往下面找找,如果不需要Tor,仅仅用Polipo的话,这三行可以不用打开
chunkHighMark = 50331648 # 这两行是控制使用的内存大小,打开即可
objectHighMark = 16384
Just save and exit afterwards! Open Polipo in the same way as open Tor
systemctl start polipo
Polipo's default agent is on port 8123, which can be changed by itself. After the above operations, we can see if the configuration is complete, and we can use the nmap tool
nmap localhost -p 8123
You can see that the port has been opened, and it is used by Polipo. Now we can see if port 8123 is proxying our http request? We use it to access websites ifconfig.me
(does not require root permissions)
curl --proxy localhost:8123 ifconfig.me
You can see that this website returned our current IP address.
This IP address is not our current IP address. On the one hand, it proves that our Tor is successfully opened and connected to Polipo. On the other hand, it proves that we successfully proxy http requests on port 8123, and you're done. !
If you need to turn off these two proxies, then
systemctl stop polipo
systemctl stop tor
If you don't want to remember these commands, you can write a script to install the commands in it, one-click startup and shutdown