I want to be able to remotely ssh into my rpi, while my rpi is connected to PIA (via OpenVPN). I can ssh into the pi from my local network while the pi is connected to OpenVPN, and I can also ssh into the pi remotely while the pi is not connected to OpenVPN. But when I try to ssh into the pi remotely while the pi is connected to OpenVPN I get a connection timeout.
My idea was to connect to PIA, request port forwarding, set the ssh port to the port being forwarded, and then ssh pi@PIA_IP -p PIA_PORT. I thought this would work but I just get a connection timeout.
I tried these commands to route ssh traffic through my router, but still get connection timeout:
sudo ip route add default via <ROUTER_IP> table 65 sudo ip route flush cache sudo iptables -t mangle -A OUTPUT -p tcp --sport 22 -j MARK --set-mark 65
EDIT: got it work work by doing this:
sudo ip rule add fwmark 65 table novpn sudo ip route add default via <LOCAL_ROUTER_IP> dev eth0 table novpn sudo ip route flush cache sudo iptables -t mangle -A OUTPUT -p tcp --sport 2022 -j MARK --set-mark 65 sudo iptables -A INPUT -i tun0 -p tcp -m tcp --dport 2022 -j DROP
After running these commands, start OpenVPN. Then I forwarded port 2022 on my router to my pi, and connected with:
ssh pi@<PUBLIC_ROUTER_IP> -p 2022