How does a Mac choose between Wi-Fi and Ethernet to work with? [duplicate]
My Mac is connected via a 1GBit Ethernet. However, from time to time I do turn on WiFi and let it connect, typically because I need to use AirDrop etc.
When I'm done with AirDrop I usually turn the Wi-Fi off and stay on Ethernet.
My thinking is that "wifi is slower" and my Mac may use it when downloading or uploading instead of my fast Ethernet. Now I realize this is not based on anything else other than fear.
Is there truth to my fear?
If a Mac has two active connections, Wi-fi, and Ethernet -- what will it choose to use when I'm uploading a large file? Is there a possibility it would choose to use the slower Wifi connection? Or does it employ some kind of algorithm to figure out which one to use based on availability, type and speed?
It's possible to set network access interface priority order. Go to System Preferences → Network, click on the lock icon to unlock the preference pane. Now click on the gear icon shown towards the bottom of the network interface list, and select Set Service Order... command.
Now, in the new pane that opens, you can drag the priority network interface (Ethernet in your case) to top.
(I do not have a LAN interface, so the same isn't visible in the screenshot).
In a default setup, macOS will prefer the ethernet connection over the WiFi connection automatically. You do not need to fear that you're limiting your network speeds by also connecting to WiFi.
You can change the default order by opening System Preferences, select Network, click on the Gear icon below the interface list and select "Set Service Order". There you can drag the interfaces to prioritize.
You can also list the current order from Terminal.app with:
networksetup -listnetworkserviceorder
And change the default order by running the following command:
networksetup -ordernetworkservices <service1> <service2> <service3> <...>
where <service1>
etc. needs to replaced by the service names listed by the previous command.
If you have a slightly more advanced network setup, or are interested in networking - you need to know that the above mentioned answer (and the other answers here) are really a simplification of what actually happens.
Technically it is not so that the highest ordered interface is always used for network communication.
For example if the WiFi and Ethernet connections really connect to two different IP networks (i.e. two different LANs) - then macOS will route packets destined for local computers over the correct interface - so that computers only accessible through WiFi will be transmitted to over WiFi. This is handled by ordinary IP routing.
In addition, if you have a more specific route for a destination (rather than the default gateway) - then it will be routed over that interface instead of the one you have chosen as the top pick in the service order. This can often be the case with VPN software that inserts more specific routes for all or parts of the IP network.
Also the simple answer might seem a bit odd if you're familiar with networking on Windows or Linux - as macOS is actually different in this respect.
On Windows and Linux the choice of which route to use when there's multiple available at the same specificity, is actually determined by a metric on the route itself. This is different than on macOS where it is determined by a metric (the service order) on the interface.
Additionally, macOS actually automatically provides source routing in this case (contrary to other systems). This means that even though you have chosen for example "Ethernet" as your top pick, then if another computer contacts yours via the WiFi connection, your Mac will respond via the WiFi connection instead of the Ethernet. Even in the case, where if you had initiated the connection yourself, it would have taken place over Ethernet.