Ssh – How to set up ssh server with VPN tunnel? (Policy routing for sshd service)

debianlinuxroutingsshvpn

It's difficult to me to explain in words, so I made diagrams.

In short, I want this to work:
The Goal

Basically I want to be able to connect from my laptop [A] to my desktop [B] via ssh, and run terminal program over OpenVPN connection, let's say IRC client for example.

So far I have working sshd, OpenVPN tunnel, and port forwarding on my router, but seems like port is closed (or not being forwarded), I get connection timeout. I also tried without VPN and that failed as well.

Edit:
When [B] runs without OpenVPN it accepts connections to External IP,
when it runs with OpenVPN it doesn't.

I have no idea what is wrong.


Strangely (for me) this is working ok:

enter image description here

I can connect from [A] to [B] [A]$ ssh [B].local_IP,
and connect from [B](over VPN) to [B](WAN IP) [B]$ ssh [B].WAN_IP.
I hope this makes sense. In this configuration port forwarding seems to work, also sshd working locally; in previous configuration port forwarding is not working(?).


I thought it should be easy, but it's not. Searching google is futile.

My router is Belkin F5D8636-4 v1 (01), potential candidate for causing trouble, but I would rather exclude every other possibility before buying new one.

Edit 2):
I stumbled upon this post, but the answer doesn't work for me. After fiddling with policy routing I had some success, however it created some other problems, and I learned I have no comprehension of routing tables 🙁
I believe however, the solution is in policy routing.

Any advice appreciated.

Best Answer

Yes, I found answer here (by coincidence).
This setup on the [B] machine solved the problem:

ip rule add from 192.168.1.X table 128
ip route add table 128 to 192.168.1.0/24 dev eth1
ip route add table 128 default via 192.168.1.1

I guess credits to user AGWA.

Related Question