Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Route all internet traffic through Tor

Do not use in production Server or if you don't know what iptables do

Add this to torrc ( located on /etc/tor/torrc):


AutomapHostsOnResolve 1

TransPort 9051 

DNSPort 9053

Run the attached script as root so all traffic will route from Tor. you can also use attached torrc as a sample.

# ignored location
# Enter your tor UID
# Tor's Port. default is 9050 but if you changed it in torrc change next line
iptables -F
iptables -t nat -F
iptables -t nat -A OUTPUT -m owner --uid-owner $UID -j RETURN
#Change if you select another port for Tor DNS in torrc. I select 9053. Also DNS default port is 53
iptables -t nat -A OUTPUT -p udp --dport 53 -j REDIRECT --to-ports 9053
for NET in $IGN; do
iptables -t nat -A OUTPUT -d $NET -j RETURN
iptables -t nat -A OUTPUT -p tcp --syn -j REDIRECT --to-ports $PORT
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
for NET in $IGN; do
iptables -A OUTPUT -d $NET -j ACCEPT
iptables -A OUTPUT -m owner --uid-owner $UID -j ACCEPT
iptables -A OUTPUT -j REJECT
#set tor socks proxy to 9052
SocksPolicy accept
UseBridges 1
#Here is an example of tor bridges. you can obtain it from:
Bridge obfs4 IP:port KEY cert=CERT iat-mo$
ClientTransportPlugin obfs4 exec /usr/bin/obfs4proxy
AutomapHostsOnResolve 1
#Tor tansport
TransPort 9051
#tor DNS port
DNSPort 9053
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment