Could you explain how to route all internet traffic through tor? I am using Ubuntu I really don't know how to do it. Actually I am using tor for twitter only, and I'm afraid of DNS leak. So I need to route everything through tor.


You are looking for this: TransparentProxy.

Local Redirection Through Tor

Add to your torrc:

AutomapHostsOnResolve 1
TransPort 9040
DNSPort 53

This way you setup DNS server on your Ubuntu on port 53 and Transparent proxy:

Next, add to your /etc/resolv.conf


This way, you prevent any DNS leakage from your system.

Therefore, configure your firewall in the light that any connection will going through TransPort except Tor's user:


# destinations you don't want routed through Tor

# the UID Tor runs as

# Tor's TransPort

iptables -F
iptables -t nat -F

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
for NET in $NON_TOR; do
 iptables -t nat -A OUTPUT -d $NET -j RETURN
iptables -t nat -A OUTPUT -p tcp --syn -j REDIRECT --to-ports $TRANS_PORT

iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
for NET in $NON_TOR; do
 iptables -A OUTPUT -d $NET -j ACCEPT
iptables -A OUTPUT -m owner --uid-owner $TOR_UID -j ACCEPT
iptables -A OUTPUT -j REJECT

Keep reading official wiki, there is kind of attack against this method and kind of solution: IsolatingProxy.

  • What do you do with this shell script? Run it once? Run it on bootup? Put it in a specific place so that Tor can run it? – Aaron Franke Sep 26 '20 at 8:00
  • Run it on boot. This is necessary since iptables rules are not persistent across reboot. Tor doesn't run the script. If NetworkManager is enabled or you manually use the ifup and ifdown commands to bring interfaces up and down, put the script in /etc/network/if-pre-up.d/ then it will run everytime an interface is brought up (actually the scripts in that folder are executed first by ifup, hence the name if-pre-up). Check if NetworkManager is enabled (in kali its the file /usr/sbin/update-rc.d). – jakethefinn Dec 11 '20 at 12:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.