Pick a working network interface for the bridged `rd0` vmnet interface
See original GitHub issueThe host interface is specified in ~/Library/Application\ Support/rancher-desktop/lima/_config/networks.yaml
:
networks:
bridged:
mode: bridged
interface: en0
This must be set before the sudoers file is created:
$ grep en0 /etc/sudoers.d/rancher-desktop-lima
/opt/rancher-desktop/bin/vde_vmnet --pidfile=/private/var/run/rancher-desktop-lima/bridged_vmnet.pid --vde-group=staff --vmnet-mode=bridged --vmnet-interface=en0 /private/var/run/rancher-desktop-lima/bridged.ctl, \
So the default configuration only works if en0
is connected to a network that provides a DHCP server.
Some suggestions to find the network automatically:
Using networksetup
This will work on older macOS versions like Mojave, but requires parsing plain text output:
$ networksetup -listnetworkserviceorder
An asterisk (*) denotes that a network service is disabled.
(1) Ethernet
(Hardware Port: Ethernet, Device: en0)
(2) Wi-Fi
(Hardware Port: Wi-Fi, Device: en1)
(3) Bluetooth PAN
(Hardware Port: Bluetooth PAN, Device: en4)
[...]
This provides all network services in priority order, and the device name.
Then query each device in turn:
$ networksetup -getinfo "Ethernet"
DHCP Configuration
Client ID:
IPv6: Automatic
IPv6 IP address: none
IPv6 Router: none
Ethernet Address: 38:c9:86:21:6d:c1
$ networksetup -getinfo "Wi-Fi"
DHCP Configuration
IP address: 192.168.17.21
Subnet mask: 255.255.0.0
Router: 192.168.17.1
Client ID:
IPv6: Automatic
IPv6 IP address: none
IPv6 Router: none
Wi-Fi ID: 28:f0:76:12:69:14
This shows that en0
has no IP address, and that en1
should be configured for the bridged network.
Using system_profiler SPNetworkDataType -json
The -json
option is only supported on macOS Catalina and later. It is possible to parse the regular output, but feels rather brittle.
I don’t see this documented, but it looks like the network devices are also returned in priority order:
$ system_profiler SPNetworkDataType -json | jq '.SPNetworkDataType[] | [._name, .interface, .ip_address]'
[
"Ethernet",
"en0",
null
]
[
"Wi-Fi",
"en1",
[
"192.168.17.21"
]
]
[
"Bluetooth PAN",
"en4",
null
]
...
This means we could select the device to use like this:
$ system_profiler SPNetworkDataType -json | jq -r 'first(.SPNetworkDataType[] | select(.ip_address) | .interface)'
en1
Roaming
This is out-of-scope for this issue, but I wanted to mention that we’ll eventually have to deal with roaming too: A laptop can travel to different networks, so the bridged network address may change. Ethernet may be plugged in and Wi-Fi disconnected. Rancher Desktop should detect these situations and prompt the user to restart the VM to adapt.
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (7 by maintainers)
@manno Yes, but do the earlier entries have an IP address. I suggested this check to determine the interface to use:
However, using
route get default
may be a better option indeed.Just for the record, one user on Slack could not get a DHCP address on
en0
, even though it was the active (and only) network connection they had. This happened on their office network, but not on their home network. We could not figure out what was causing this, and switched to a “shared” network to make RD useable for them.I wonder if e.g. their Wifi setup does not allow multiple MAC addresses on a single radio (not really sure how this works). Or if the MAC addresses need to be on some kind of allow-list.