将 Tor 设置为透明代理

将 Tor 设置为透明代理

我一直在关注这个指南Tor 项目

问题是我不知道如何处理 iptables 规则集。我应该把它复制到哪里?我已经使用 Tor 网络多年了,但只在 Tails 上使用。我对修改 Tor 内容和 iptables 还不熟悉。

iptables 规则集:

#!/bin/sh

### set variables
#destinations you don't want routed through Tor
_non_tor="192.168.1.0/24 192.168.0.0/24"

#the UID that Tor runs as (varies from system to system)
_tor_uid="109"

#Tor's TransPort
_trans_port="9040"

### flush iptables
iptables -F
iptables -t nat -F

### set iptables *nat
iptables -t nat -A OUTPUT -m owner --uid-owner $_tor_uid -j RETURN
iptables -t nat -A OUTPUT -p udp --dport 53 -j REDIRECT --to-ports 53

#allow clearnet access for hosts in $_non_tor
for _clearnet in $_non_tor 127.0.0.0/9 127.128.0.0/10; do
   iptables -t nat -A OUTPUT -d $_clearnet -j RETURN
done

#redirect all other output to Tor's TransPort
iptables -t nat -A OUTPUT -p tcp --syn -j REDIRECT --to-ports $_trans_port

### set iptables *filter
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

#allow clearnet access for hosts in $_non_tor
for _clearnet in $_non_tor 127.0.0.0/8; do
   iptables -A OUTPUT -d $_clearnet -j ACCEPT
done

#allow only Tor output
iptables -A OUTPUT -m owner --uid-owner $_tor_uid -j ACCEPT
iptables -A OUTPUT -j REJECT

编辑:

我搜索了一下,发现我可以运行,sudo iptables-save > iptables.conf然后用 Tor iptables 规则集替换 iptables.conf 中的信息,然后运行,iptables-restore < iptables.conf但提示错误

iptables-restore:第 5 行失败

我应该怎么办?

答案1

这只是众多可能方法之一:

将该脚本文件放在任何地方。例如,我的位于/home/doug/init/doug_firewall

确保权限正确,以便执行。例如我的:

$ ls -l /home/doug/init/doug_firewall
-rwxr-xr-x 1 doug doug 60254 Jul  3 09:52 /home/doug/init/doug_firewall

然后编辑/etc/network/intrefaces文件以在启动时执行脚本。例如我的:

$ cat /etc/network/interfaces
# interfaces file for smythies.com 2016.01.30
#       attempt to set local DNS herein, as the method
#       used with the old 12.04 server no longer works.
#
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback
pre-up /home/doug/init/doug_firewall
dns-nameservers 127.0.0.1

# The primary interface (d-link PCI card)
auto enp4s0
iface enp4s0 inet dhcp

# Local network interface (uses built in ethernet port)
auto enp2s0
iface enp2s0 inet static
  address 192.168.111.1
  network 192.168.111.0
  netmask 255.255.255.0
  broadcast 192.168.111.255

相关内容