赞
踩
kernel menuconfig
- <M> USB Gadget Drivers
-
- <M> Ethernet Gadget (with CDC Ethernet support)
-
- [*] RNDIS support
启动linux,加载g_ether驱动
- # modprobe g_ether
- [ 318.955068] using random self ethernet address
- [ 318.959586] using random host ethernet address
- [ 318.964711] usb0: HOST MAC 9e:cd:8c:e2:e1:63
- [ 318.969052] usb0: MAC ba:ae:51:91:76:54
- [ 318.972924] using random self ethernet address
- [ 318.977379] using random host ethernet address
- [ 318.981934] g_ether gadget: Ethernet Gadget, version: Memorial Day 2008
- [ 318.988564] g_ether gadget: g_ether ready
- [ 318.992590] dwc2 f6000000.usb_otg: bound driver g_ether
查看USB虚拟网卡:USB0就是
- # ifconfig
- eth0 Link encap:Ethernet HWaddr 02:67:AB:81:02:BB
- UP BROADCAST MULTICAST MTU:1500 Metric:1
- RX packets:0 errors:0 dropped:0 overruns:0 frame:0
- TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:1000
- RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
- Interrupt:16 Base address:0x1000
-
- lo Link encap:Local Loopback
- inet addr:127.0.0.1 Mask:255.0.0.0
- UP LOOPBACK RUNNING MTU:65536 Metric:1
- RX packets:0 errors:0 dropped:0 overruns:0 frame:0
- TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:1
- RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
-
- usb0 Link encap:Ethernet HWaddr BA:AE:51:91:76:54
- inet addr:169.254.169.223 Bcast:169.254.255.255 Mask:255.255.0.0
- UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
- RX packets:25 errors:0 dropped:21 overruns:0 frame:0
- TX packets:9 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:1000
- RX bytes:4369 (4.2 KiB) TX bytes:1598 (1.5 KiB)
用USB线连接PC机,配置IP
enp0s20f0u10 为PC识别到的USB网卡设备:
- OptiPlex-3050:~$ ifconfig
- enp0s20f0u10 Link encap:Ethernet HWaddr 9e:cd:8c:e2:e1:63
- inet addr:10.42.0.1 Bcast:10.42.0.255 Mask:255.255.255.0
- inet6 addr: fe80::b0a1:e9ef:39b5:a0b5/64 Scope:Link
- UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
- RX packets:155598 errors:0 dropped:2 overruns:0 frame:0
- TX packets:77909 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:1000
- RX bytes:233303187 (233.3 MB) TX bytes:5155821 (5.1 MB)
-
- enp1s0 Link encap:Ethernet HWaddr e4:54:e8:9b:55:23
- inet addr:10.10.46.239 Bcast:10.10.47.255 Mask:255.255.254.0
- inet6 addr: fe80::73c5:dab2:c7c0:8fb6/64 Scope:Link
- UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
- RX packets:112393 errors:0 dropped:4 overruns:0 frame:0
- TX packets:12121 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:1000
- RX bytes:34254996 (34.2 MB) TX bytes:939336 (939.3 KB)
-
- lo Link encap:Local Loopback
- inet addr:127.0.0.1 Mask:255.0.0.0
- inet6 addr: ::1/128 Scope:Host
- UP LOOPBACK RUNNING MTU:65536 Metric:1
- RX packets:67007 errors:0 dropped:0 overruns:0 frame:0
- TX packets:67007 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:1000
- RX bytes:4993833 (4.9 MB) TX bytes:4993833 (4.9 MB)
设置同一网段,测试ping:
- # ifconfig usb0 10.42.0.2
- #
- #
- #
- # ifconfig
- eth0 Link encap:Ethernet HWaddr 02:67:AB:81:02:BB
- UP BROADCAST MULTICAST MTU:1500 Metric:1
- RX packets:0 errors:0 dropped:0 overruns:0 frame:0
- TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:1000
- RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
- Interrupt:16 Base address:0x1000
-
- lo Link encap:Local Loopback
- inet addr:127.0.0.1 Mask:255.0.0.0
- UP LOOPBACK RUNNING MTU:65536 Metric:1
- RX packets:0 errors:0 dropped:0 overruns:0 frame:0
- TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:1
- RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
-
- usb0 Link encap:Ethernet HWaddr BA:AE:51:91:76:54
- inet addr:10.42.0.2 Bcast:10.255.255.255 Mask:255.0.0.0
- UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
- RX packets:108 errors:0 dropped:65 overruns:0 frame:0
- TX packets:18 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:1000
- RX bytes:17442 (17.0 KiB) TX bytes:2898 (2.8 KiB)
-
- # ping 10.42.0.1
- PING 10.42.0.1 (10.42.0.1): 56 data bytes
- 64 bytes from 10.42.0.1: seq=0 ttl=64 time=0.933 ms
- 64 bytes from 10.42.0.1: seq=1 ttl=64 time=0.520 ms
- 64 bytes from 10.42.0.1: seq=2 ttl=64 time=0.486 ms
- 64 bytes from 10.42.0.1: seq=3 ttl=64 time=0.472 ms
- 64 bytes from 10.42.0.1: seq=4 ttl=64 time=0.463 ms
- 64 bytes from 10.42.0.1: seq=5 ttl=64 time=0.456 ms
- 64 bytes from 10.42.0.1: seq=6 ttl=64 time=0.561 ms
- 64 bytes from 10.42.0.1: seq=7 ttl=64 time=0.465 ms
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。