OSX Wi-fi and Ethernet network simultaneously connected and static routing

So recently I had a situation where I had my Ethernet and Wifi connected to 2 different networks in my MAC OS X, and I had a very specific use case for this

I needed to use the Ethernet connection to access 1 specific host (an internal web service), the connection through the ethernet cable allowed this but did not allow internet access, the Wifi connection allowed internet access but will not allow access to the internal web service, so basically what I needed was :

  • Have both connections active
  • Access the internal web service through the Ethernet connection
  • Access all the other hosts through the Wi-fi connection

Just connecting both interfaces does not work I was either getting access to the internet or either access to the internal WebService; if you check this article over at apple OS X network interfaces priority you can see that you can change the priority used by the system to route the requests; so if you change the priority of the Wi-fi to be on top you get internet access but not access to the internal network, and vice-versa

Sure you can make it work this way but it's really painful to have to manually change the interfaces priority to accommodate what you are trying to do at that moment

The solution that I found is to add a static route to that host; this can be easily done in a few steps (you will need for this the IP of the internal host you are trying to access)

  1. Give your Wi-fi interface the highest priority (put it on top), for this you can refer to the apple link cited above
  2. Identify the interface names, for that execute the following command on the terminal netstat -nr (in my case en0 is the ethernet interface whereas the Wi-fi is the en1)
Add a static route for the specific host (10.120.136.57) telling it to use the gateway of the Ethernet interface by running the following command in the terminal
sudo route add -host 10.120.136.57 10.247.131.1

And that should be it, please note that restarting the PC will probably remove the static route from the routing table so you will have to re-add it

Popular posts from this blog

Multi-hop ssh tunnel - howto : Creating a SSH tunnel with port forwarding between multiple hosts

Spring boot and spring data jpa tutorial - A sample application using spring 4.0 spring boot and JPA (part 2/2)

Scala : easily load an parse configuration files