6ulx使用USB虚拟网卡 6ull支持USB虚拟网卡,通过otg连接到pc,在pc中可以成usb虚拟网卡,可以像普通网卡一样传输数据。 1.内核配置开启虚拟网卡功能,需要配置内核: > Device Drivers > USB support > USB Gadget Support <M> USB Gadget Drivers [*] Ethernet Control Model (CDC ECM) [*] RNDIS 配置后重新编译内核及模块,6ulx Linux4.1.15的内核当中,默认已经开启了以上内容,可以直接按照以下步骤测试。 2.开启虚拟网卡使用以下命令加载模块驱动: $ depmod $ modprobe g_ether using random self ethernet address using random host ethernet address usb0: HOST MAC 9a:da:f1:04:bd:87 usb0: MAC 3e:93:31:de:b3:be using random self ethernet address using random host ethernet address g_ether gadget: Ethernet Gadget, version: Memorial Day 2008 g_ether gadget: g_ether ready 使用ifconifg可以查看到usb0网卡: $ ifconfig usb0 usb0 Link encap:Ethernet HWaddr 3e:93:31:de:b3:be BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame: TX packets:0 errors:0 dropped:0 overruns:0 carrie collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) 设置虚拟网卡的IP: $ ifconfig usb0 up $ ifconfig usb0 192.168.3.100 将网卡挂载到虚拟机上的Ubuntu,Ubuntu上可以看到该网卡: forlinx@ubuntu:~$ ifconfig ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.16.0.176 netmask 255.255.0.0 broadcast 172.16.255.255 inet6 fe80::440:9f3c:1bdf:7dcf prefixlen 64 scopeid 0x20<link> ether 00:0c:29:04:0c:5a txqueuelen 1000 (Ethernet) RX packets 1758930 bytes 325617111 (325.6 MB) RX errors 0 dropped 1 overruns 0 frame 0 TX packets 23984 bytes 4206273 (4.2 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ens160u2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet6 fe80::cb43:4c6c:14e3:52c5 prefixlen 64 scopeid 0x20<link> ether 9a:da:f1:04:bd:87 txqueuelen 1000 (Ethernet) RX packets 2 bytes 354 (354.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 45 bytes 8169 (8.1 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 3218438 bytes 298605151 (298.6 MB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 3218438 bytes 298605151 (298.6 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ens160u2即为USB网卡,设置Ubuntu上虚拟网卡IP: forlinx@ubuntu:~$ sudo ifconfig ens160u2 192.168.3.200 ping测试: forlinx@ubuntu:~$ ping 192.168.3.200 PING 192.168.3.200 (192.168.3.200) 56(84) bytes of data. 64 bytes from 192.168.3.200: icmp_seq=1 ttl=64 time=0.051 ms 64 bytes from 192.168.3.200: icmp_seq=2 ttl=64 time=0.066 ms
|