Wireless comes in two aspects:
- the wireless hardware device phy, usually named phyX.
- its associated network interface(s) dev usually named wlanY.
For a given wireless hardware device phyX, it's even possible to create additional network interfaces associated to it, when it has the capabilities to do so. That's how it's possible for example to use the same card (when it has the capability) to be both a client and an access point at the same time. And that's probably why there's an additional layer. This lower layer is all managed with the iw
command rather than the ip link
command which controls only the final network interface.
Separately from this, the system can choose to rename (from wlanY) the network interface according to the so-called Consistent network interface device naming or also called Predictable Network Interface Names. This is an unrelated topic, since it won't help any better to guess the association between phyX (which is typically dynamic) and whatever name.
iw
's man page is almost empty, but the command has still a (very) large help page.
# iw help | less
[...]
dev
List all network interfaces for wireless hardware.
dev <devname> info
Show information for this interface.
[...]
For a given network interface wlanY, using iw dev wlanY info
will display in its results an entry called wiphy
and an index. That's the index X of the matching phy interface. So you can get the wlanY -> phyX relation.
Example:
# iw dev wlan1 info
Interface wlan1
ifindex 45
wdev 0x300000001
addr 16:c3:0c:a5:63:62
type managed
wiphy 3
txpower 0.00 dBm
Or you can get the list of hardware devices sorted per phyX (displayed phy#X
) with their matching network interfaces. Eg:
# iw dev
phy#4
Interface wlan2
ifindex 46
wdev 0x500000001
addr 2a:5f:7f:7a:30:1b
type managed
txpower 0.00 dBm
phy#3
Interface wlan1
ifindex 45
wdev 0x300000001
addr 16:c3:0c:a5:63:62
type managed
txpower 0.00 dBm
phy#0
Interface wlan0
ifindex 3
wdev 0x1
addr be:2d:23:03:29:c5
type managed
txpower 0.00 dBm
And rfkill displays the relation between rfkillZ and phyX (beside LTE modem and bluetooth).
# rfkill -o ID,TYPE,DEVICE,SOFT,HARD list
ID TYPE DEVICE SOFT HARD
0 wlan phy0 unblocked unblocked
4 wlan phy3 unblocked unblocked
5 wlan phy4 unblocked unblocked
9 bluetooth hci0 blocked unblocked
By navigating through symlinks and reading contents available in /sys/class/
the information is also available, in more than one possible way:
from wlan to phy to rfkill:
$ ls -l /sys/class/net/wlan1/phy80211
lrwxrwxrwx. 1 root root 0 Sep 1 20:58 /sys/class/net/wlan1/phy80211 -> ../../ieee80211/phy3
$ grep ^ /sys/class/net/*/phy80211/name
/sys/class/net/wlan0/phy80211/name:phy0
/sys/class/net/wlan1/phy80211/name:phy3
/sys/class/net/wlan2/phy80211/name:phy4
$ ls -1d /sys/class/net/*/phy80211/rfkill*
/sys/class/net/wlan0/phy80211/rfkill0
/sys/class/net/wlan1/phy80211/rfkill4
/sys/class/net/wlan2/phy80211/rfkill5
from rfkill to phy to wlan:
$ ls -l /sys/class/rfkill/rfkill4/device
lrwxrwxrwx. 1 root root 0 Sep 1 21:05 /sys/class/rfkill/rfkill4/device -> ../../phy3
$ grep ^ /sys/class/rfkill/rfkill*/device/name
/sys/class/rfkill/rfkill0/device/name:phy0
/sys/class/rfkill/rfkill4/device/name:phy3
/sys/class/rfkill/rfkill5/device/name:phy4
$ ls -1d /sys/class/rfkill/rfkill*/device/device/ieee80211/*
/sys/class/rfkill/rfkill0/device/device/ieee80211/phy0
/sys/class/rfkill/rfkill4/device/device/ieee80211/phy3
/sys/class/rfkill/rfkill5/device/device/ieee80211/phy4
(the bluetooth device above has a different layout and is thus not displayed like this)
ls -1d /sys/class/rfkill/rfkill*/device/device/net/*
/sys/class/rfkill/rfkill0/device/device/net/wlan0
/sys/class/rfkill/rfkill4/device/device/net/wlan1
/sys/class/rfkill/rfkill5/device/device/net/wlan2
# iw phy phy4 interface add onemorewlan type managed addr 12:34:56:78:ab:cd
$ ls -1d /sys/class/ieee80211/phy*/device/net/*
/sys/class/ieee80211/phy0/device/net/wlan0
/sys/class/ieee80211/phy3/device/net/wlan1
/sys/class/ieee80211/phy4/device/net/onemorewlan
/sys/class/ieee80211/phy4/device/net/wlan2
You get the idea.