I have a server (192.168.1.1) that I use as a router/default gateway. This server connects to an openvpn and routes all network through this vpn before sending it (encrypted) to the modem (192.168.1.254). I have configured port forwarding so that SSH connections on my public IP get routed to the server. The IP from the vpn can't be used to connect to the server.
Whenever I disconnect the vpn I can access the server with SSH from a remote location but when routing through the VPN this is impossible. This all seems logical as the server tries to reply from a different IP.
What I wish is want the server keeps routing my LAN traffic through the VPN but accepts SSH on my public IP. Thus if you will routing all traffic from the modem to the server and back to the modem again. I could then specify rules on the server that only allow SSH connections. Another perhaps better option is that only SSH (22) gets routed through the modem. The problem is that I can't get this routing from the modem to server and back again to work.
What I tried:
I found this source where they suggest the following:
ip rule add from 192.168.1.1 table 128 ip route add table 128 to 192.168.1.0 dev eth0 ip route add table 128 default via 192.168.1.254
Which feels like undoing all the previous vpn routing I have done before. Whenever I do this I can still acces the server from a remote location but the VPN won't work anymore.