0

Is there any way to tell an application to use a specific network interface? I'Ve got the problem that iMessage and other apps need to run on the proxy-free wifi network while other apps such as Xcode need to run on ethernet to connect to the repository in the wired network.

Is there any way to do this?

0

1 Answer 1

1

Some programs specifically gives you the option to choose the source interface. That's the easiest way if this is the case.

Another possibility is to use source routing (policy routing) to ensure that requests from your specific source is routed via the interface you need. This is often quite complicated to setup and maintain.

A third possibility, which is really not about choosing a specific interface, is a practical approach where you change the routing based on the destination instead.

I.e. if it is only important for you that your app uses the wired ethernet conncetion when talking to the specific repository, you could determine which IP address (or addresses) that repository has - and then add a specific route for that IP over the wired interface. This route would take priority over your default route.

From the Terminal run:

  route -n add -host xxx.xxx.xxx.xxx -interface en0

(for net local)

or

  route -n add -host xxx.xxx.xxx.xxx gw yyy.yyy.yyy.yyy -interface en0

(for routed destinations)

where xxx.xxx.xxx.xxx should be replaced with the IP of the repository. Similarly yyy.yyy.yyy.yyy is to be replaced with the IP of your gateway for the wired interface.

If you have several wired interfaces, change en0 to the specific interface.

If your repository have multiple IP addresses, run the command above multiple times with the various IPs.

10
  • how would I then use ssh in the wired network? can I specify an interface on the fly when I type in ssh user@hostname -I en0 or something like that? Commented Jul 25, 2018 at 13:24
  • Almost... you can write: "ssh user@hostname -b xxx.xxx.xxx.xxx" where xxx is the IP of your wired network interface (i.e. your own IP).
    – jksoegaard
    Commented Jul 25, 2018 at 16:57
  • sudo route -n add -host 10.248.226.15 -gw 10.248.225.1 -interface en7 results in route: bad address: gw Commented Jul 26, 2018 at 7:54
  • I also had the idea of routing everything in the wired network through the wired connection: everything that I need to access in the wired network has a 10.XXX.XXX.XXX. address. Can I specify that? The means, I would primarily use wifi but for 10.X addresses I would use wired? Is that possible that way? Commented Jul 26, 2018 at 7:57
  • Yes, just replace "-host xxx.xxx.xxx.xxx" with "-net 10.0.0.0/8"
    – jksoegaard
    Commented Jul 26, 2018 at 10:47

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