如果让linux 中的ethxx 设备 改名

应用场景:

    有些公司想将模块换成合宙的模块,但是之前的模块出现的是USBxx 网卡,合宙的是ethxx ,这让就让应用程序改动应用程序,很是麻烦!

修改方法:

方法一  修改脚本 

       1.找到文件  /etc/udev/rules.d/70-persistent-net.rules    将SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="ac:00:00:c9:1e:c5", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*"  改成  SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="ac:00:00:c9:1e:c5", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="usb*",

方法二  修改内核   

step 1:

For Linux Kernel Version newer than 2.6.30
File: [KERNEL]/drivers/
net/usb/usbnet.c

  1. usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
  2. {
  3. net->netdev_ops = &usbnet_netdev_ops;
  4. net->watchdog_timeo = TX_TIMEOUT_JIFFIES;
  5. net->ethtool_ops = &usbnet_ethtool_ops;
  6. / allow device-specific bind/init procedures
  7. // NOTE net->name still not usable ...
  8. if (info->bind) {
  9. status = info->bind (dev, udev);
  10. if (status < 0)
  11. goto out1;
  12. // heuristic: "usb%d" for links we know are two-host,
  13. // else "eth%d" when there's reasonable doubt. userspace
  14. // can rename the link if it knows better.
  15. if ((dev->driver_info->flags & FLAG_ETHER) != 0 &&
  16. ((dev->driver_info->flags & FLAG_POINTTOPOINT) == 0 ||
  17. (net->dev_addr [0] & 0x02) == 0))
  18. strcpy (net->name, "eth%d"); /**** 请将此处修改为 strcpy (net->name, "usb%d"); */
  19. /* WLAN devices should always be named "wlan%d" */
  20. if ((dev->driver_info->flags & FLAG_WLAN) != 0)
  21. strcpy(net->name, "wlan%d");
  22. /* WWAN devices should always be named "wwan%d" */
  23. if ((dev->driver_info->flags & FLAG_WWAN) != 0)
  24. strcpy(net->name, "wwan%d");

    

For Linux Kernel Version newer than 2.6.30
File: [KERNEL]/drivers/usb/serial/option.c

  1. static int option_probe(struct usb_serial *serial,
  2. const struct usb_device_id *id)
  3. {
  4. struct usb_interface_descriptor *iface_desc =
  5. &serial->interface->cur_altsetting->desc;
  6. struct usb_device_descriptor *dev_desc = &serial->dev->descriptor;
  7. /* Never bind to the CD-Rom emulation interface */
  8. if (iface_desc->bInterfaceClass == 0x08)
  9. i return -ENODEV;
  10. //+add by airm2m for Air72x
  11. if(dev_desc->idVendor == cpu_to_le16(0x1286) &&
  12. dev_desc->idProduct == cpu_to_le16(0x4e3d) &&
  13. iface_desc->bInterfaceNumber <= 1)
  14. return -ENODEV;
  15. //-add by airm2m for Air72x
  16. /*
  17. * Don't bind reserved interfaces (like network ones) which often have
  18. * the same class/subclass/protocol as the serial interfaces. Look at
  19. * the Windows driver .INF files for reserved interface numbers.
  20. */
  21. if (is_blacklisted(
  22. iface_desc->bInterfaceNumber,
  23. OPTION_BLACKLIST_RESERVED_IF,
  24. (const struct option_blacklist_info *) id->driver_info))
  25. return -ENODEV;

优先推荐使用方法2

    

上次更新 2021-01-28