I have configured a router to route all traffic from an internal interface through the TOR network. Therefore, every client that uses this router as its Gateway will access the internet through TOR, regardless which application is running. This is my setup on the router:

- eth2 is the internal device (
- TOR listens on eth2 for connections from LAN clients
- eth0 is the device that connects to the internet

My torrc setup:


My iptables on the Gateway ( is the client that may connect):

-A PREROUTING -i eth2 -p udp -m udp --dport 53 -j REDIRECT --to-ports 9053
-A PREROUTING -i eth2 -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j REDIRECT --to-ports 9040
-A INPUT -s -i eth2 -p udp -m udp --dport 9053 -j ACCEPT
-A INPUT -s -i eth2 -p tcp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -i eth0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A OUTPUT -d -o eth2 -j ACCEPT
-A OUTPUT -o eth0 -m conntrack --ctstate NEW,RELATED,ESTABLISHED -j ACCEPT

To test that no DNS requests are leaked I used the method described here. However, it does not give an example of what the expected results should be. So I issued the following commands and got the following output:

$ tcpdump -pni eth2 'port domain'
18:59:33.158511 IP > 20625+ AAAA? check.torproject.org. (38)
18:59:33.212772 IP > 15545+ A? check.torproject.org. (38)
18:59:33.448883 IP > 20625 NXDomain 0/0/0 (38)
18:59:33.451545 IP > 58625+ AAAA? check.torproject.org. (38)
18:59:33.539581 IP > 15545 1/0/0 A (54)
18:59:33.808832 IP > 58625 NXDomain 0/0/0 (38)
18:59:33.810768 IP > 61942+ A? check.torproject.org. (38)
18:59:34.072359 IP > 61942 1/0/0 A (54)

I ran also ran the commands on the outgoing device eth0

tcpdump -pni eth0

which yielded no output at all.

I have two questions:

  1. Does the output of tcpdump proof that no DNS requests from the client were leaked?
  2. Are the iptables rules reasonable for my purpose?
  • You probably want to remove RELATED from ACCEPTed the conntrack states.
    – cacahuatl
    Oct 5, 2017 at 21:07
  • Regarding the observed traffic, you have to consider where IPTables is picking this up. For the best indication of any leaks, you want to sniff upstream of the Tor Router (I.E. between it and the internet). (note that Tor Routers are in general a bad idea unless you've made extensive changes to your operating systems default behaviour). You are likely seeing these packets before they hit the REDIRECT rule.
    – cacahuatl
    Oct 6, 2017 at 1:39
  • @canonizingironize Why are TOR routers a bad idea? Can you point me to a source where the caveats are described in detail? Oct 6, 2017 at 10:03
  • Using ethernet, you can skip the stuff about wireless cryptography but I've written some of the points up here: github.com/epidemics-scepticism/writing/blob/master/…
    – cacahuatl
    Oct 6, 2017 at 16:06

1 Answer 1


Android devices do ignore DHCP DNS server, remember. So - it looks like this? I've met this problem too. The only really working workaround is to forcibly route all dns requests to and to the port 9053 in yor case - and block the IP addresses of and to be routed through Tor, I've found no other way

  • -A PREROUTING -i eth2 -p udp -m udp --dport 53 -j REDIRECT --to-ports 9053 that's literally already happening...
    – cacahuatl
    Oct 5, 2017 at 22:52
  • yes, but just to be 100% sure I do recommend to block the addresses on by-ip basis, so no other possibilities will be there. Also it fixes Android client problem, when you can not resolve dot-onion names just by joining the network.
    – Alexey Vesnin
    Oct 5, 2017 at 23:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .