SSH into Raspberry Pi connected to PIA

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 [email protected]_IP -p PIA_PORT. I thought this would work but I just get a connection timeout.

Comments

  • 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
    

    Then I forwarded port 2022 on my router to my pi, and connected with:

    ssh [email protected]<PUBLIC_ROUTER_IP> -p 2022
  • Sure isn't plug-n-play, is it? LOL

    Good job!
Sign In or Register to comment.