Given one host (router) with the following netfilter rule in order to redirect incoming TCP packets to it's tor proxy service:
-A PREROUTING -p tcp --syn -j REDIRECT --to-ports 9040
Also given second host (client) configured to use the tor router as gateway:
sudo ip route add 1.2.3.4 via ${TOR_ROUTER_IP}
Now, when I establish a TCP connection (HTTP) to 1.2.3.4, it hangs at "TCP_NODELAY set" for a bit before finally timing out:
curl -v https://1.2.3.4
* Trying 1.2.3.4...
* TCP_NODELAY set
While I run this command I can see the corresponding counter on the router increase constantly, using the following command:
iptables -t nat -L -v -n
This confirms that the rule mentioned at the beginning is actually applied. However, apparently no response is returned to the client (the curl command).
Consequently, I suspect an error in the iptables rules. But what is that error and how can it be resolved?
(Sidenote: I doubt it to be relevant, but the router is actually a docker container.)
Update: Here is the output of netstat -tulpen
on the router:
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:9040 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:9050 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.11:36045 0.0.0.0:* LISTEN -
udp 0 0 127.0.0.11:45140 0.0.0.0:* -
udp 0 0 0.0.0.0:5353 0.0.0.0:* -