I'd like to route some apps through WiFi and other apps through ethernet. Given that OSX has a wide array of system tools and utilities as well as a rich ecosphere of apps, how can I make that happen?*
3 Answers
I'd like to route some apps through WiFi and other apps through ethernet.
Unfortunately, this is not the way it (networking) works. You can't say that you want Safari to go through one network port and iTunes to come through another. The problem with this lies in the fact the applications themselves don't make the network connection - it makes a call to the networking (Berkeley sockets) API that makes the connection and binds the process to the socket itself.
In the simplest terms, the flow looks like this
When your local process (the application in question) wants to make a connection, it requests that a socket be created. Part of that request includes the IP address, the connection is then made, and the app is bound to it. The app then sends and receives data through that socket.
The key to remember here is that the application asks for a socket based on the network address. Other than (assuming you're on a network with a single segment), you have only two routes:
- your local network
- everything else (i.e. Internet)
If you have two interfaces connected to this single network, your routes will overlap and the interface with priority will be the primary.
Whatever your application running, it's going to say, "I want to go to foo.bar.com
" which will translate to an IP address and a socket will be created over the route that gets you there. The point is, your app has no control over the matter.
However, let's say you're connected to two different networks:
Ethernet (en0) -> 1.2.3.0
WiFi (en1) -> 5.6.7.0
If there is a file server with an IP of 1.2.3.4, all traffic bound for that address will go through the Ethernet. If your WiFi is configured for Internet access, all calls to 1.2.3.0 and every other address will go through en1. Again, your app has no say in the matter and the socket will be made based on destination.
Can an application use a specific network interfcace?
Yes, of course it can, but this is something done at the source level of the application because it's the one making the call to the API. If you code it to use a specific interface, it will do so (it's not practical in any sense, but you have the ability).
Bottom line: For an external application to re-route traffic based on the application you use, it would have to insert itself between the application and the protocol stack of the OS and that is just not going to happen.
It depends on what apps we're talking about and what exactly you want to achieve. In some cases you can get by by using pf and policy-based routing (source routing) based on the source port or destination ports of your apps. However this is normally only possible with apps that are "simple" network wise (i.e. for example only connects to a single serveR).
A generic solution does not seem to exist yet in a neatly packaged form you can just download and use without special expertise.
If you want to implement such a solution, you will want to use the DYLD_INSERT_LIBRARIES environment variable when launching your apps to inject your own shared library into the process. That shared library should then override the bind() call to make sure that the process binds to the IP of either your WiFi or Ethernet interface depending on the app.
The closest thing i can think of for this is called packet prioritization (so apps would not be on the same Ethernet connection interfering with each other)it is available in the motherboard "Fatal1ty Z370 Professional Gaming i7" but it is a $200 board and it is a hardware solution, I do not believe there is a software capable of this but i could be wrong i hope this helped.