ザキンコのブログ

ザキンコの日記のはてなブログ版です。

Debian 10 (buster) にtorを入れてOnion routerにするメモ

Torくらいはさくっと設定できないといけないのでやってみた。

家のルータに有線でOnion routerを接続して、その下に有線の別のネットワークを作る。
元々Raspberry Pi 2 Bに入れて動いていたのだけど、アップデートしたら前まで使えてたUSB LANアダプタが電気食いすぎ警告が出て使えなくなったので、余ってるPCに最新のDebian 10 (buster) を入れて設定してみることにした。

機種はLenovo H520sで、インストールは簡単だろうと思ってDebianのインストールUSBを作って入れたら、インストール後に再起動したらOSが起動しない。
UEFIでインストールしたけどUEFIで起動できないようなので、BIOSでセキュアブート無効にして再インストールすればいいやと思ったら設定が無い。
起動時F12でブートの選択をしてUSBメモリの非UEFIインストーラーを選択して起動して解決。

デスクトップ環境はXfcesshd入れて、プリンタは外してインストール。
イーサーネットの名前(うちではenp3s4f0,enp3s4f1)をメモっておく。オンボードカニチップはファームが必要なので無視。

ここを参考にtorをインストールしてみる。以下、設定。
https://learn.adafruit.com/onion-pi/
http://www.neko.ne.jp/~freewing/raspberry_pi/raspberry_pi_3_tor_anonymous_proxy/

# rootに
su -

# イーサーネットの設定
nano /etc/network/interfaces

auto enp3s4f0
allow-hotplug enp3s4f0
iface enp3s4f0 inet dhcp

auto enp3s4f1
allow-hotplug enp3s4f1
iface enp3s4f1 inet static
  address 192.168.42.1/24

# 必要だったら ifdown -a && ifup -a

# apt の update
apt update

# DHCPサーバー
# isc-dhcp-server は古いので KEA を使えとのことだが、まだ使えるのでとりあえず
# https://www.isc.org/dhcp/
# https://www.isc.org/kea/
apt install isc-dhcp-server

# DHCP の設定1
nano /etc/default/isc-dhcp-server

INTERFACES="enp3s4f1"

# DHCP の設定2
nano /etc/dhcp/dhcpd.conf

subnet 192.168.42.0 netmask 255.255.255.0 {
	range 192.168.42.2 192.168.42.254;
	option broadcast-address 192.168.42.255;
	option routers 192.168.42.1;
	default-lease-time 600;
	max-lease-time 7200;
	option domain-name "local";
	option domain-name-servers 192.168.42.1;
}

# DHCPサーバーの起動もしくは再起動
systemctl start isc-dhcp-server
systemctl restart isc-dhcp-server


# tor のインストール
apt install tor

# tor の設定
# TransListenAddress,DNSListenAddress は obsolete なので書かない
nano /etc/tor/torrc

Log notice file /var/log/tor/notices.log
VirtualAddrNetwork 10.192.0.0/10
AutomapHostsSuffixes .onion,.exit
AutomapHostsOnResolve 1
TransPort 192.168.42.1:9040
DNSPort 192.168.42.1:53

# log の設定
touch /var/log/tor/notices.log
chown debian-tor /var/log/tor/notices.log
chmod 644 /var/log/tor/notices.log

# tor の起動もしくは再起動
systemctl start tor
systemctl restart tor

# iptables の設定
# iptables は nftables に置き換わるようだけど、まだ使えるのでそのまま
iptables -F
iptables -t nat -F

iptables -t nat -A PREROUTING -i enp3s4f1 -p tcp --dport 22 -j REDIRECT --to-ports 22
iptables -t nat -A PREROUTING -i enp3s4f1 -p udp --dport 53 -j REDIRECT --to-ports 53
iptables -t nat -A PREROUTING -i enp3s4f1 -p tcp --syn -j REDIRECT --to-ports 9040

iptables -t nat -L

sh -c "iptables-save > /etc/iptables.ipv4.nat"

# /etc/network/interfaces に起動時にロードするように設定

nano /etc/network/interfaces

# 末尾に追加
pre-up iptables-restore < /etc/iptables.ipv4.nat

Onion router のネットワークにPCを繋いで動作確認。

以上。少し面倒だった。
IPFire(https://www.ipfire.org/) のTorがきちんと動けばそれを使おうと思ってたけど、動かなかったので自分で設定。