当前位置:   article > 正文

[嵌入式linux]将linux板卡虚拟为USB网卡设备(Ethernet Gadget)_enp0s20f0u1u6是什么网卡

enp0s20f0u1u6是什么网卡

 

kernel menuconfig

  • -> Device Drivers ->USB support -> USB Gadget Support
  • 建议最好选成M,作为内核驱动模块,便于与其他Gadget驱动共存
  1. <M>   USB Gadget Drivers 
  2. <M>     Ethernet Gadget (with CDC Ethernet support)
  3. [*]       RNDIS support
  • 更新uImage和rootfs

 

启动linux,加载g_ether驱动

  1. # modprobe g_ether
  2. [ 318.955068] using random self ethernet address
  3. [ 318.959586] using random host ethernet address
  4. [ 318.964711] usb0: HOST MAC 9e:cd:8c:e2:e1:63
  5. [ 318.969052] usb0: MAC ba:ae:51:91:76:54
  6. [ 318.972924] using random self ethernet address
  7. [ 318.977379] using random host ethernet address
  8. [ 318.981934] g_ether gadget: Ethernet Gadget, version: Memorial Day 2008
  9. [ 318.988564] g_ether gadget: g_ether ready
  10. [ 318.992590] dwc2 f6000000.usb_otg: bound driver g_ether

查看USB虚拟网卡:USB0就是

  1. # ifconfig
  2. eth0 Link encap:Ethernet HWaddr 02:67:AB:81:02:BB
  3. UP BROADCAST MULTICAST MTU:1500 Metric:1
  4. RX packets:0 errors:0 dropped:0 overruns:0 frame:0
  5. TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
  6. collisions:0 txqueuelen:1000
  7. RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
  8. Interrupt:16 Base address:0x1000
  9. lo Link encap:Local Loopback
  10. inet addr:127.0.0.1 Mask:255.0.0.0
  11. UP LOOPBACK RUNNING MTU:65536 Metric:1
  12. RX packets:0 errors:0 dropped:0 overruns:0 frame:0
  13. TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
  14. collisions:0 txqueuelen:1
  15. RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
  16. usb0 Link encap:Ethernet HWaddr BA:AE:51:91:76:54
  17. inet addr:169.254.169.223 Bcast:169.254.255.255 Mask:255.255.0.0
  18. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
  19. RX packets:25 errors:0 dropped:21 overruns:0 frame:0
  20. TX packets:9 errors:0 dropped:0 overruns:0 carrier:0
  21. collisions:0 txqueuelen:1000
  22. RX bytes:4369 (4.2 KiB) TX bytes:1598 (1.5 KiB)

用USB线连接PC机,配置IP

  • Windows系统的PC机需安装RNDIS虚拟网卡驱动(下面PC是用的ubuntu)
  • PC识别成功后会出现新的网卡设备
  • 配置PC和板卡两端IP为同一网段

enp0s20f0u10 为PC识别到的USB网卡设备:

  1. OptiPlex-3050:~$ ifconfig
  2. enp0s20f0u10 Link encap:Ethernet HWaddr 9e:cd:8c:e2:e1:63
  3. inet addr:10.42.0.1 Bcast:10.42.0.255 Mask:255.255.255.0
  4. inet6 addr: fe80::b0a1:e9ef:39b5:a0b5/64 Scope:Link
  5. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
  6. RX packets:155598 errors:0 dropped:2 overruns:0 frame:0
  7. TX packets:77909 errors:0 dropped:0 overruns:0 carrier:0
  8. collisions:0 txqueuelen:1000
  9. RX bytes:233303187 (233.3 MB) TX bytes:5155821 (5.1 MB)
  10. enp1s0 Link encap:Ethernet HWaddr e4:54:e8:9b:55:23
  11. inet addr:10.10.46.239 Bcast:10.10.47.255 Mask:255.255.254.0
  12. inet6 addr: fe80::73c5:dab2:c7c0:8fb6/64 Scope:Link
  13. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
  14. RX packets:112393 errors:0 dropped:4 overruns:0 frame:0
  15. TX packets:12121 errors:0 dropped:0 overruns:0 carrier:0
  16. collisions:0 txqueuelen:1000
  17. RX bytes:34254996 (34.2 MB) TX bytes:939336 (939.3 KB)
  18. lo Link encap:Local Loopback
  19. inet addr:127.0.0.1 Mask:255.0.0.0
  20. inet6 addr: ::1/128 Scope:Host
  21. UP LOOPBACK RUNNING MTU:65536 Metric:1
  22. RX packets:67007 errors:0 dropped:0 overruns:0 frame:0
  23. TX packets:67007 errors:0 dropped:0 overruns:0 carrier:0
  24. collisions:0 txqueuelen:1000
  25. RX bytes:4993833 (4.9 MB) TX bytes:4993833 (4.9 MB)

设置同一网段,测试ping:

  1. # ifconfig usb0 10.42.0.2
  2. #
  3. #
  4. #
  5. # ifconfig
  6. eth0 Link encap:Ethernet HWaddr 02:67:AB:81:02:BB
  7. UP BROADCAST MULTICAST MTU:1500 Metric:1
  8. RX packets:0 errors:0 dropped:0 overruns:0 frame:0
  9. TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
  10. collisions:0 txqueuelen:1000
  11. RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
  12. Interrupt:16 Base address:0x1000
  13. lo Link encap:Local Loopback
  14. inet addr:127.0.0.1 Mask:255.0.0.0
  15. UP LOOPBACK RUNNING MTU:65536 Metric:1
  16. RX packets:0 errors:0 dropped:0 overruns:0 frame:0
  17. TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
  18. collisions:0 txqueuelen:1
  19. RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
  20. usb0 Link encap:Ethernet HWaddr BA:AE:51:91:76:54
  21. inet addr:10.42.0.2 Bcast:10.255.255.255 Mask:255.0.0.0
  22. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
  23. RX packets:108 errors:0 dropped:65 overruns:0 frame:0
  24. TX packets:18 errors:0 dropped:0 overruns:0 carrier:0
  25. collisions:0 txqueuelen:1000
  26. RX bytes:17442 (17.0 KiB) TX bytes:2898 (2.8 KiB)
  27. # ping 10.42.0.1
  28. PING 10.42.0.1 (10.42.0.1): 56 data bytes
  29. 64 bytes from 10.42.0.1: seq=0 ttl=64 time=0.933 ms
  30. 64 bytes from 10.42.0.1: seq=1 ttl=64 time=0.520 ms
  31. 64 bytes from 10.42.0.1: seq=2 ttl=64 time=0.486 ms
  32. 64 bytes from 10.42.0.1: seq=3 ttl=64 time=0.472 ms
  33. 64 bytes from 10.42.0.1: seq=4 ttl=64 time=0.463 ms
  34. 64 bytes from 10.42.0.1: seq=5 ttl=64 time=0.456 ms
  35. 64 bytes from 10.42.0.1: seq=6 ttl=64 time=0.561 ms
  36. 64 bytes from 10.42.0.1: seq=7 ttl=64 time=0.465 ms

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/码创造者/article/detail/991626
推荐阅读
相关标签
  

闽ICP备14008679号