17

I want to connect remotely using SSH.

However, I'm not able to while my VPN is active, so I disconnect from the VPN and then connect using the other connection.

How can I force the connection through my other connection when connected to the VPN?

I'm using Windows 7 and PuTTY client.

1
  • 3
    Please add more information... Provide a routing table of your current machine, what your client OS is (linux, windows)
    – RomeNYRR
    Aug 13, 2012 at 15:51

3 Answers 3

17

There are 2 options. First, you could modify your routes so that the SSH packets naturally go through the correct interface.

Or you could use the -b SSH option (or in a similar way the -B one):

     -b bind_address
             Use bind_address on the local machine as the source address of
             the connection.  Only useful on systems with more than one
             address.

It will bind your SSH client to a chosen local IP address, so that all packets will be emitted through the associated interface.

4
  • 1
    what's the second option? i'm curious! May 1, 2016 at 14:59
  • 2
    It would also be helpful to know how to do the equivalent in PuTTY, since the question specified that client. Jun 15, 2016 at 17:06
  • It looks like the -b option does not support an IPv6 IP. Am I correct?
    – Arya
    Oct 5, 2017 at 18:30
  • not supported on putty Dec 18, 2019 at 13:19
7

The issue was with the route taken.

The solution was to update the routing table. I used the route command to add a new route specifying the correct interface and gateway.

The command looks like route add <destination> mask <netmask> <gateway> <interface>, for example:

route -p add 10.100.10.10 mask 255.255.255.0 192.168.1.0 IF 13

-p is for persistent so it remains there after reboot. IF is for interface and you can get this number from the command route print.

0
4

You must change the route towards your destination.

A previous answer stated that the -b or -B options can be used, but normally, if the VPN is activated this does not work because it reroutes the traffic towards any destination through the VPN network interface - generally named tun0.

Therefore, you must reconfigure the route taken to reach your destination. Let us call it <destination>, and <gate1> the IP address of the gateway (technically the address of the nexthop router) associated to the different interface that you want to use. With ip route, route being deprecated, this should be:

ip route add <destination> via <gate1>

An alternative is

ip route add <destination> via <gate1> dev <different interface>

but given that the address <gate1> is already associated with your different interface, here <different interface>, that changes nothing.

What matters here, is to specify it is <gate1>, the gateway of your different interface, which has to be traversed, instead of that of the VPN.

1
  • 1
    This worked for me with sudo ip route add 192.168.1.0/24 via 192.168.1.241 dev eth0 to access the 192.168.1.xxx subnet via eth0 (metric 300, IP address 192.168.1.241) instead of wlan0 (metric 200 = higher preference) Dec 7, 2021 at 22:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .