Search code examples
macososx-mountain-lion

route add application net traffic


Recently I´ve been changed from a building in my job and I have a small issue. Do you know how can I route a traffic to a specified gateway but only when SSH y used?

I have in my macmini 2 network interfaces, the lan and the wifi. - Lan IP Addres: 10.0.70.16 gateway 10.0.0.101 ( Local network) - Wifi IP Addres: 192.168.1.188 gateway 192.168.1.1 (Internet access)

Everything works fine but I have a server with a 192.168.1.1 (diferent network) and it is accesible throught LAN network using route add 192.168.1.1 10.0.0.101 command. But If I do that, I lost my Internet access.

I need to route my traffic only when accessing to 192.168.1.1 using SSH. Any clue?

Thanks in advance


Solution

  • The problem is you have two hosts with the ip address

    192.168.1.1
    

    The route change you made disconnects you because the Default Gateway for your Wifi is 192.168.1.1. So your mac will try to route all traffic leaving your mac via wifi to that host. You are telling the mac to route to that via the wired interface instead. I suspect that whatever is on the wired Lan with 192.168.1.1 is not operating as a router so it is not forwarding your traffic on and thus your traffic is being dropped.

    If you are using the ssh client that comes with OSX, it supports the BindAddress option (see the man page for ssh_config) which you could try using to bind to your wired lan port and try to ssh to the 192.168.1.1 ip like this:

    ssh -o BindAddress=10.0.70.16 192.168.1.1
    

    This should send ssh traffic to your lan gateway 10.0.0.101 destined for 192.168.1.1 which it should forward on to the network that the 192.168.1.1 you are trying to reach is on.