When working with multiple USB-to-Ethernet adapters on a Linux system, it can be challenging to determine which physical device corresponds to which network interface (e.g., eth0, eth1). This becomes particularly important when you need to configure specific adapters or troubleshoot connection issues.
The most reliable way to map interfaces to physical devices is through the sysfs filesystem. Here's how to do it:
for dev in /sys/class/net/*; do
echo "Interface: $(basename $dev)"
echo "Device path: $(readlink -f $dev/device)"
echo "USB port: $(lsusb -t | grep $(basename $(readlink -f $dev/device)))"
echo "------------------------"
done
This script will show you the interface name, the associated device path, and the USB port information for each network interface.
The udevadm
command provides detailed information about devices:
udevadm info -a -p $(udevadm info -q path -n eth0)
Replace eth0
with your interface name. Look for the ATTR{address}
(MAC address) and ATTR{dev_id}
values in the output.
You can correlate USB devices with their physical ports using:
lsusb -t
This shows the USB device tree with port numbers. Combine this with the interface information from the previous methods to create a complete mapping.
To ensure consistent interface naming across reboots, you can create udev rules:
# First, get the MAC address of your adapter
ip link show eth1
# Then create a udev rule
echo 'SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="00:1a:2b:3c:4d:5e", NAME="wan0"' > /etc/udev/rules.d/10-network.rules
This will rename the interface with MAC address 00:1a:2b:3c:4d:5e to "wan0" persistently.
- Use
dmesg | grep usb
to see USB device connection logs - Check
/var/log/syslog
for interface initialization messages - Try physically disconnecting and reconnecting devices while monitoring the logs
When working with multiple USB-to-Ethernet adapters on a Linux system, mapping physical devices to their corresponding network interfaces (eth0, eth1, etc.) can be tricky. The interfaces often get assigned dynamically, making consistent identification difficult across reboots.
The most reliable method is to use udevadm
, which provides detailed information about USB devices and their associated interfaces:
udevadm info -a -p $(udevadm info -q path -n eth0) | grep -E "ATTR{devpath}|ATTR{idVendor}|ATTR{idProduct}|ATTR{interface}|DRIVERS"
This command shows the USB device path, vendor ID, product ID, and driver information for the specified interface.
You can traverse the sysfs filesystem to find the physical-device-to-interface mapping:
ls -l /sys/class/net/eth0/device readlink -f /sys/class/net/eth0/device
This will show you the actual USB device associated with eth0.
Here's a bash script that automates the identification process for all interfaces:
#!/bin/bash for interface in $(ls /sys/class/net | grep -E 'eth|enp|eno'); do echo -n "$interface: " udevadm info -q path -n $interface 2>/dev/null | cut -d'/' -f4- | xargs basename echo "USB Details:" udevadm info -a -p $(udevadm info -q path -n $interface) | \ grep -E "ATTR{idVendor}|ATTR{idProduct}|ATTR{serial}" | \ sed 's/^ *//' echo "------------------------" done
For long-term solutions, consider creating udev rules to maintain consistent naming:
# /etc/udev/rules.d/70-persistent-net.rules SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="00:1a:2b:3c:4d:5e", NAME="lan0" SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="00:1a:2b:3c:4d:5f", NAME="wan0"
Replace the MAC addresses with those of your actual devices.
Sometimes examining the physical USB hierarchy helps:
lsusb -t lsusb -v
This shows the USB port numbers where each device is connected, which can be correlated with interface information.