I'm running a tor router on a Raspberry Pi with following iptables rules (wlan0
: internal net with clients / wlan1
: Internet):
:INPUT DROP [12:3771]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [544:242321]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -m state --state INVALID -j DROP
-A INPUT ! -s 192.0.0.0/8 -i wlan0 -j LOG --log-prefix "SPOOFED PKT "
-A INPUT ! -s 192.0.0.0/8 -i wlan0 -j DROP
-A INPUT -i lo -j ACCEPT
-A INPUT -i wlan0 -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 0 -j ACCEPT
-A FORWARD -m state --state INVALID -j DROP
-A FORWARD -p icmp -m icmp --icmp-type 8 -j ACCEPT
-A FORWARD -p icmp -m icmp --icmp-type 0 -j ACCEPT
-A OUTPUT -m conntrack --ctstate INVALID -j DROP
-A OUTPUT -m state --state INVALID -j DROP
-A OUTPUT ! -s 127.0.0.1/32 ! -d 127.0.0.1/32 ! -o lo -p tcp -m tcp --tcp-flags RST,ACK RST,ACK -j DROP
COMMIT
# Completed on Sat Mar 18 22:30:17 2023
# Generated by iptables-save v1.8.7 on Sat Mar 18 22:30:17 2023
*nat
:PREROUTING ACCEPT [609109:124689904]
:INPUT ACCEPT [272613:29686827]
:OUTPUT ACCEPT [2131:306630]
:POSTROUTING ACCEPT [1583:253278]
-A PREROUTING -d 192.168.42.1/32 -i wlan0 -p tcp -j REDIRECT
-A PREROUTING -i wlan0 -p tcp -j REDIRECT --to-ports 9040
-A PREROUTING -i wlan0 -p udp -m udp --dport 53 -j REDIRECT --to-ports 9053
-A PREROUTING -i wlan0 -p udp -j REDIRECT --to-ports 9040
-A POSTROUTING -o wlan1 -j MASQUERADE
COMMIT
All is working fine. Using the browser on the client (connected to wlan0
) to reach https://check.torproject.org/
shows that tor is used. I would like to add ip tables rules to exclude certain domains from being routed through tor. These domains should be forwarded from the client to the destination and directly connect to the destination as we have with a simple NAT/MASQUERADING situation. For example, if we set the rule to exclude check.torproject.org
(or the equivalent IP address we get from dig check.torproject.org +short
), using the browser on the client should show me that tor is not anymore used.
I tried the following command to add such a rule:
sudo iptables -t nat -I PREROUTING 1 -i wlan0 -d `dig check.torproject.org +short`/32 -j ACCEPT
and alternatively:
sudo iptables -t nat -I PREROUTING 3 -i wlan0 -d <IPADRESS>/32 -j ACCEPT
I also tried it in combination with:
sudo iptables -I FORWARD 1 -i wlan0 -d <IPADRESS>/32 -j ACCEPT
In all these cases, the browser on the client, loading https://check.torproject.org/
will do it forever. It seems that the browser doesn't get any response back. Do I have to add another iptables rule, or am I completely wrong?