I am trying to reroute traffic from specific devices in my house over openvpn. For this, I've created an OpenVPN tunnel between my house wifi router and my server.
Here is my setup:
Wifi router's outgoing interface IP: 192.168.1.102 Wifi router's openvpn tun0: 10.8.0.2 Server's openvpn tun0: 10.8.0.1 My PC WiFi Server ,- 10.8.0.2(tun0) 10.8.0.1(tun0) --. | | _ __ _ ' .-,( ),-. ' |-| [__]|=| wireless ___|_ VPN .-( )-. VPN |=| /::/|_| <- - - - - > [__...] < - - - > ( internet ) < - > |=| . '-( ).-' "^" | '-.( ).-' `-- 192.168.1.102
Server's iptable configuration:
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE iptables -A FORWARD -i eth0 -o tun0 -m state --state RELATED, ESTABLISHED -j ACCEPT iptables -A FORWARD -i tun0 -o eth2 -j ACCEPT
Wifi router's configuration (with a new routing table openvpn-route):
ip route add default via 10.8.0.1 dev tun0 table openvpn-route ip rule add fwmark 0x1 table openvpn-route iptables -t mangle -A PREROUTING -m mac --mac-source aa:aa:aa:aa:aa:aa -j MARK --set-mark 1 iptables -A POSTROUTING -t nat -o tun0 -p tcp --dport 80 -j SNAT --to 10.8.0.2
Now whenever I access sites from my laptop, I see traffic going to wifi router's tun device and from there to the server. However, the SRC IP address of the traffic is 192.168.1.102 (outgoing interface IP of the wifi router). Because of this, I think the server ignores this traffic.
When I look at how many packets matched SNATing rule to change SRC IP to 10.8.0.2, I see that count as zero. So that rule is not getting matched for any packet.
How can I fix this?