LoginSignup
5
7

More than 5 years have passed since last update.

AWS:EC2にtorをインストールしたメモ

Last updated at Posted at 2016-05-18

1.torインストール
https://www.torproject.org/download/download.html
からSource CodeをDL
サーバにgzをscpして

$ tar xzvf tor-0.2.7.6.tar.gz
で解凍
$ cd tor*
$ ./configure
を実行したら"libeventがない"云々でエラーが出たので
$ sudo yum install libevent libevent-devel
後念のためこれも
$ sudo yum install zlib openssl openssl-devel
再度
$ ./configure
$ make
$ sudo make install
$ sudo cp /usr/local/etc/tor/torrc.sample /usr/local/etc/tor/torrc
$ cd /usr/local/etc/tor

2.torrcを編集

$ sudo vi torrc
torrc
SOCKSPort 9050 # Default: Bind to localhost:9050 for local connections.
SOCKSPort (接続元IP):9100 

SOCKSPolicy accept 127.0.0.1/32
SOCKSPolicy accept (接続元IP)/32
SOCKSPolicy reject *

SOCKSPortはポート設定9050はlocalhost=127.0.0.1のときの設定で、ローカルで使う分にはこれで十分
他のサーバから接続可能にするときは9100を使う設定
SOCKSPolicyは上から適用。

3.tor起動

$ /usr/local/bin/tor
こんな風に出てくればOK。初回だけ結構時間かかる
[notice] Bootstrapped 90%: Establishing a Tor circuit
[notice] Tor has successfully opened a circuit. Looks like client functionality is working.
[notice] Bootstrapped 100%: Done

4.接続
別の画面からこれを実行して
curl --socks5 localhost:9050 http://www.ugtop.com/spill.shtml

「現在接続している場所(IPv4)」
のグローバルIP
が書き換わっていること確認


polipoなどhttp proxyを入れなくてもいけた。
user-agentとかがブラウザっぽく設定できるかはあとで試す。

===PEAR::HTTP/Request2 が入っている前提でのphpサンプル===

http.php
<?php

require_once 'HTTP/Request2.php';
require_once 'HTTP/Request2/Adapter/Socket.php';

$socks = new HTTP_Request2_Adapter_Socket();

$request = new HTTP_Request2('http://taruo.net/e/');
$request->setConfig('proxy_host','localhost');
$request->setConfig('proxy_port','9050');
$request->setConfig('proxy_type','socks5');
$request->setHeader('Accept-Language','ja');
$request->setHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');

$response = $socks->sendRequest($request);
echo $response->getBody();

~~~~~~~~~~
torを通さないときはproxy_*が入った3行をコメントアウト。
PCのブラウザから試すときは
(Httpじゃなく)SOCK Proxyを設定
Tor is not an HTTP ProxyとでるのはHTTPでアクセスしようとしたとき

EC2のセキュリティグループのインバウンドで9050を通す。

■参照サイト
http://d.hatena.ne.jp/knaka20blue/searchdiary?word=%2A%5BTor%5D
http://ohwhsmm7.blog28.fc2.com/blog-entry-450.html

5
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
7