Is it possible to set a MacBook Pro to use ethernet cable over the wifi when it tries to access a certain IP in .bashrc file or any other configuration file?

For example, you can set it not to use a proxy when it is routing on my private IP using the following command.

export NO_PROXY=

Is there any way to ask my laptop to use the ethernet cable instead of the wifi connection for that specific IP?

  • Looks like this question was answered here
    – Tim D
    Oct 14 '15 at 14:40

There are two things you can do here.

If you want all your traffic to go via built-in Ethernet if both Ethernet and Wifi are up, you can make it more preferred in System Preferences:

System Preferences -> Network will show you the window with all Network connections defined. At the bottom of the left hand side panel (with the list of interfaces) you'll see three buttons: +, - and a cogwheel. Click the last one (the cogwheel) and you'll see the fourth option from the top - "Set Service Order". If you drag Ethernet above Wifi after you click that option, then if both are active, the Ethernet will be preferred.

If, however, you want to have selected traffic go via Ethernet while the default traffic to go via Wifi then it's a bit more complicated and would generally involve the use of Command Line and specifically the route command.

There's a few scenarios here, so I'll ask a few questions now that might point you in the right direction, or could let me help with a better answer:

  1. Are both the WIFI and the Ethernet interfaces on the same LAN? i.e. will they have an IP address from the same range? will they use the same default gateway?

  2. Is the destination IP address in the same LAN that either the WIFI or the Ethernet are on? or is the destination IP address "somewhere on the Internet"?

For now I'll give you the answer for the easiest scenario, which is that the WIFI and Ethernet are on different LANs and that the destination IP is on the Internet.

Let's say the WIFI gets an IP address and the default gateway to use to get to the Internet is Let's also say that the Ethernet gets an IP address and that the default gateway to use to get to the Internet out via the Ethernet is

Let's also assume that you want to route all traffic via WIFI by default, but at the same time you want all traffic to a host with the IP to go via Ethernet.

In that case, you need to go through the procedure I described at the start and make sure that the WIFI is ABOVE the Ethernet (therefore is more preferred).

Then open the Terminal and issue the following command:

sudo route add -host

You will need to enter your own password when asked by sudo command.

If you have more than one IP address to which you'd like to add routes via Ethernet, you can run more route commands.

Now, you need to be aware that each time you disconnect the Ethernet link, the routes will disappear and you'll have to manually enter them again in Terminal. If you'd like it automated, you can look at launchd - have a look through the manuals for route and launchd.plist - in Terminal just type man route and man launchd.plist. One of the variables you're interested in for launchd is NetworkState. Please note, I didn't have the need to do something like that automatically (however I did use it manually at times) and so don't have a ready solution. Some scripting, etc would be required, but at least this should get you going.

You must log in to answer this question.

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