# How to associate ETH number with USB port number for Huawei?

## orion777

Good day!

I'm using more than one 4G Huawei 3372h modems. These dongles mode of operation is HiLink, so I have to use usb_modeswitch to operate them. The problem is that these dongles are one-by-one copies.. there are no any differences in ether, serial number and so.. and there are no possibilities to change serial or ether. 

When the system is booted, dongles are recognized as eth1, eth2, ... but the numbering is always random, depending on how fast modem is connected to the cellular network.

I want to hardly associate USB PORT numbers with eth numbers (to be able to specify static IP settings). 

This link https://askubuntu.com/questions/49910/how-to-distinguish-between-identical-usb-to-serial-adapters says that it is possible to recognize two identical devices by using USB Port numbers. However, I am newbee and cant understand HOW to do this..

I'm trying to run lsusb, but the dongle is always recognized as a device 005 independently on what usb port is used (You can replug, but after restart it becomes 005 again).

```
pi64 /etc # lsusb

Bus 001 Device 005: ID 12d1:14dc Huawei Technologies Co., Ltd. E33372 LTE/UMTS/GSM HiLink Modem/Networkcard

Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter

Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. SMC9514 Hub

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

```

I was trying to run pi64 /etc/udev/rules.d # udevadm monitor --udev --property to understand what port is used, but seems that the Huawei 3372h in HiLink mode does not build any ttyUSB or so.. 

https://paste.pound-python.org/show/qHzB084A7E4UylX9M12t/

It will be great to get some help, advises or some links to read.. Please remember that I;m not an experience linux user and udev man does not have examples on device mapping based on USB port number.

----------

## krinn

you should plug 2 of them at least when showing the result, to see if really your assertion is true ; because network device do use their mac address to carry informations, and as such, two identical mac address would flaw the communication.

once two are plug, just show udevadm info -qall /sys/class/net/eth* result

----------

## orion777

eth0 is build-in Raspberry pi 3B ethernet.

Both dongles are connected and are recognized as eth1 and eth2 respectively. 

As I understood, udevadm info -qall /sys/class/net/eth*  * symbol should to be replaced with 1 or 2, as * symbol returns eth0 only. So here is eth1 and eth2 reports:

```

pi64 ~ # udevadm info -qall /sys/class/net/eth1

P: /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/1-1.5:1.0/net/eth1

E: DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/1-1.5:1.0/net/eth1

E: ID_BUS=usb

E: ID_MM_CANDIDATE=1

E: ID_MM_HUAWEI_NDISDUP_SUPPORTED=1

E: ID_MODEL=HUAWEI_MOBILE

E: ID_MODEL_ENC=HUAWEI_MOBILE

E: ID_MODEL_FROM_DATABASE=E33372 LTE/UMTS/GSM HiLink Modem/Networkcard

E: ID_MODEL_ID=14dc

E: ID_NET_NAME_MAC=enx0c5b8f279a64

E: ID_REVISION=0102

E: ID_SERIAL=HUAWEI_MOBILE_HUAWEI_MOBILE

E: ID_TYPE=generic

E: ID_USB_CLASS_FROM_DATABASE=Communications

E: ID_USB_DRIVER=cdc_ether

E: ID_USB_INTERFACES=:020600:0a0600:080650:

E: ID_USB_INTERFACE_NUM=00

E: ID_VENDOR=HUAWEI_MOBILE

E: ID_VENDOR_ENC=HUAWEI_MOBILE

E: ID_VENDOR_FROM_DATABASE=Huawei Technologies Co., Ltd.

E: ID_VENDOR_ID=12d1

E: IFINDEX=4

E: INTERFACE=eth1

E: SUBSYSTEM=net

E: USEC_INITIALIZED=14388886

pi64 ~ # udevadm info -qall /sys/class/net/eth2

P: /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/net/eth2

E: DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/net/eth2

E: ID_BUS=usb

E: ID_MM_CANDIDATE=1

E: ID_MM_HUAWEI_NDISDUP_SUPPORTED=1

E: ID_MODEL=HUAWEI_MOBILE

E: ID_MODEL_ENC=HUAWEI_MOBILE

E: ID_MODEL_FROM_DATABASE=E33372 LTE/UMTS/GSM HiLink Modem/Networkcard

E: ID_MODEL_ID=14dc

E: ID_NET_NAME_MAC=enx0c5b8f279a64

E: ID_REVISION=0102

E: ID_SERIAL=HUAWEI_MOBILE_HUAWEI_MOBILE

E: ID_TYPE=generic

E: ID_USB_CLASS_FROM_DATABASE=Communications

E: ID_USB_DRIVER=cdc_ether

E: ID_USB_INTERFACES=:020600:0a0600:080650:

E: ID_USB_INTERFACE_NUM=00

E: ID_VENDOR=HUAWEI_MOBILE

E: ID_VENDOR_ENC=HUAWEI_MOBILE

E: ID_VENDOR_FROM_DATABASE=Huawei Technologies Co., Ltd.

E: ID_VENDOR_ID=12d1

E: IFINDEX=5

E: INTERFACE=eth2

E: SUBSYSTEM=net

E: USEC_INITIALIZED=15256471

```

And here is lsusb:

```

pi64 ~ # lsusb

Bus 001 Device 008: ID 12d1:14dc Huawei Technologies Co., Ltd. E33372 LTE/UMTS/GSM HiLink Modem/Networkcard

Bus 001 Device 006: ID 12d1:14dc Huawei Technologies Co., Ltd. E33372 LTE/UMTS/GSM HiLink Modem/Networkcard

Bus 001 Device 004: ID 1c4f:0002 SiGma Micro Keyboard TRACER Gamma Ivory

Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter

Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. SMC9514 Hub

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

```

So now, seems we know usb port numbers! )) However, I don't know what to further..

----------

## depontius

I'm sorry, but here is where it is necessary to throw in a snide comment.  Good old "eth numbers" are obsolete, because we're in the brave new world of "persistent, predictable device names."  The only problem is that they are neither persistent nor predictable, especially where USB devices are concerned.  They give a device name based on device enumeration, except that especially with USB, device enumeration can and will change depending on which devices are plugged in, and which ports they're plugged in to.

The ONLY thing that can give persistent device names is the MAC, and generally the MAC is printed somewhere on the packaging, meaning that it's predictable, too.

Please pardon the rant.  BTW, I'm still using eth-names.

----------

## orion777

depontius, Yes here is the problem what I'm talking about! As MAC-addresses are same, NetworkManager sometimes is confusing, nmtui combines eth1 and eth2 as single wired connection 2. However, on my gentoo 64 up to three dongles with the same MAC works simultaneously: the problem is that I have to plug them one after another, othervice eth nembers will be randomly assigned or dongles may fail to get DHCP assigned IPs.

So I suppose that I can't use networkmanager configured by nmtui if I want to get predictable configuration (as it is based on MACs). I found some solution in ubuntu forum, how to connect two identical usb-to-serial converters:

```
KERNEL=="ttyUSB*", KERNELS=="1-8.1.5", NAME="ttyUSB0"

KERNEL=="ttyUSB*", KERNELS=="1-8.1.6", NAME="ttyUSB1"
```

https://askubuntu.com/questions/49910/how-to-distinguish-between-identical-usb-to-serial-adapters

As can be seen from udevadm info -qall /sys/class/net/eth1 AND 2, USB ports numbers can be determinated:

```
pi64 ~ # udevadm info -qall /sys/class/net/eth1

P: /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/1-1.5:1.0/net/eth1

E: DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/1-1.5:1.0/net/eth1
```

```
pi64 ~ # udevadm info -qall /sys/class/net/eth2

P: /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/net/eth2

E: DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/net/eth2
```

The problem is that Hiawei 3372h does not build any ttyUSB* (at least I cant find them). So the question is: will it work if I will specify this:

```
KERNEL=="eth*", KERNELS=="1-1.5:1.0", NAME="eth1"
```

and, if it will work, than, probably, I have to remove NetworkManager, and manually assign all configuration in /etc/conf.d/net as is shown here https://wiki.gentoo.org/wiki/Handbook:X86/Full/Networking  ??

----------

## krinn

Well, try, it should be more aim to net subsystem and more aim to only be apply to that device and not any device plug-in that port, so something more like

```
SUBSYSTEM=="net", ACTION=="add", ENV{ID_MODEL_ID}=="14dc" KERNEL=="eth*", KERNELS=="1-1.5:1.0", NAME="myeth1"

udevadm test /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/1-1.5:1.0/net/eth1
```

also as you might note, i'm naming it "myeth1", because you don't know if eth1 will be taken or not by another device, and trying to rename to eth1 would fail if taken already.

Expect result from udevadm test:

You should see: changing net interface name from 'eth1' to 'myeth1'

----------

## depontius

 *orion777 wrote:*   

> depontius, Yes here is the problem what I'm talking about! As MAC-addresses are same, 

 

I don't think that that's legally allowed to happen.  They can certainly be the exact same model number, even purchased and manufactured at the same time.  But the MACs need to be distinct.  A quick search with the terms "gentoo udev rule mac" will give decent hits.  (No quotes on the search bar)

----------

## krinn

As stupid and surprising as it is, its mac are indeed identical, making this device a real poorly made one.

```
E: ID_NET_NAME_MAC=enx0c5b8f279a64 
```

----------

## orion777

Ok, I was trying to do it as follows:

1) make my .rules:

```
 pi64 ~ # cat /etc/udev/rules.d/70-my-network.rules

SUBSYSTEM=="net", ACTION=="add", ENV{ID_MODEL_ID}=="14dc" KERNEL=="eth*", KERNELS=="1-1.4:1.0", NAME="eth3" 
```

2) rebooting and plugging dongle into 1-1.4:1.0 port

However, its name becomes eth1, NOT eth3 as specified in 70-my-network.rules ... Maybe NetworkManager overrides this rule?

```
pi64 ~ # udevadm info -qall /sys/class/net/eth1

P: /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/net/eth1

E: DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/net/eth1

E: ID_BUS=usb

E: ID_MM_CANDIDATE=1

E: ID_MM_HUAWEI_NDISDUP_SUPPORTED=1

E: ID_MODEL=HUAWEI_MOBILE

E: ID_MODEL_ENC=HUAWEI_MOBILE

E: ID_MODEL_FROM_DATABASE=E33372 LTE/UMTS/GSM HiLink Modem/Networkcard

E: ID_MODEL_ID=14dc

E: ID_NET_NAME_MAC=enx0c5b8f279a64

E: ID_REVISION=0102

E: ID_SERIAL=HUAWEI_MOBILE_HUAWEI_MOBILE

E: ID_TYPE=generic

E: ID_USB_CLASS_FROM_DATABASE=Communications

E: ID_USB_DRIVER=cdc_ether

E: ID_USB_INTERFACES=:020600:0a0600:080650:

E: ID_USB_INTERFACE_NUM=00

E: ID_VENDOR=HUAWEI_MOBILE

E: ID_VENDOR_ENC=HUAWEI_MOBILE

E: ID_VENDOR_FROM_DATABASE=Huawei Technologies Co., Ltd.

E: ID_VENDOR_ID=12d1

E: IFINDEX=4

E: INTERFACE=eth1

E: SUBSYSTEM=net

E: USEC_INITIALIZED=125867763

```

Also 

```
udevadm test /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/net/eth3
```

returns

```
unable to open device '/sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/net/eth3'

Unload module index
```

but it work when eth1 is specified..

```
rules contain 98304 bytes tokens (8192 * 12 bytes), 22968 bytes strings

8780 strings (88086 bytes), 7189 de-duplicated (66710 bytes), 1592 trie nodes used

IMPORT builtin 'net_id' /lib/udev/rules.d/75-net-description.rules:6

IMPORT builtin 'usb_id' /lib/udev/rules.d/75-net-description.rules:8

/sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.0: if_class 2 protocol 0

IMPORT builtin 'hwdb' /lib/udev/rules.d/75-net-description.rules:8

RUN 'net.sh $name start' /lib/udev/rules.d/90-network.rules:6

created db file '/run/udev/data/n4' for '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/net/eth1'

.MM_USBIFNUM=00

ACTION=add

DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/net/eth1

ID_BUS=usb

ID_MM_CANDIDATE=1

ID_MM_HUAWEI_NDISDUP_SUPPORTED=1

ID_MODEL=HUAWEI_MOBILE

ID_MODEL_ENC=HUAWEI_MOBILE

ID_MODEL_FROM_DATABASE=E33372 LTE/UMTS/GSM HiLink Modem/Networkcard

ID_MODEL_ID=14dc

ID_NET_NAME_MAC=enx0c5b8f279a64

ID_REVISION=0102

ID_SERIAL=HUAWEI_MOBILE_HUAWEI_MOBILE

ID_TYPE=generic

ID_USB_CLASS_FROM_DATABASE=Communications

ID_USB_DRIVER=cdc_ether

ID_USB_INTERFACES=:020600:0a0600:080650:

ID_USB_INTERFACE_NUM=00

ID_VENDOR=HUAWEI_MOBILE

ID_VENDOR_ENC=HUAWEI_MOBILE

ID_VENDOR_FROM_DATABASE=Huawei Technologies Co., Ltd.

ID_VENDOR_ID=12d1

IFINDEX=4

INTERFACE=eth1

SUBSYSTEM=net

USEC_INITIALIZED=91807368

run: 'net.sh eth1 start'

Unload module index

```

----------

## orion777

I dont know why, but it work only as follows:

```
pi64 /etc/udev/rules.d # cat 70-etc3.rules

KERNELS=="1-1.4:1.0", NAME="eth3"

```

All other parameters, such as KERNEL, seems not working..

----------

## orion777

One more question: if I wish to use config in /etc/conf.d/net , than I have to disable network manager? As NetworkManager stores configs in /etc/NetworkManager/system-connections , but net file in /etc/conf.d/ does not exist.

----------

