admin管理员组文章数量:1576381
文章目录
- 1、虚拟网卡配置
- 2、Windows PC 连接测试
- 3、usb无线网卡
- 3.1、树莓派4b aarch64 Debian12
- 3.2、ubuntu18.04 接入 rtl8811c无线网卡
- 3.3、禁用某个无线网卡
- 3.4、监听模式
- 3.4.1、检查是否支持监听
- 3.4.2、开启监听
- 4、静态ip配置
- 5、dhcp服务
树莓派cm4 iobard,可经过配置将树莓派当作一个usb网卡设备,使用usb即可与树莓派进行网络通信。
1、虚拟网卡配置
修改配置文件,将树莓派usb slave配置为网卡设备linux ethernet gadget 。
- config.txt 中末行添加
dtoverlay=dwc2
- cmdline.txt 文件中的 rootwait 后添加
modules-load=dwc2,g_ether
重启树莓派生效,会增加一个 usb0
的网络设备,此时没有ip地址分配。
2、Windows PC 连接测试
使用 micro usb连接开发板和win电脑,会提示有一个RNDIS设备(部分win10可能识别为com设备,安装驱动即可 链接1, 链接2, 也可如下方式安装:右键更新驱动程序-手动查找和安装-“从计算机的可用驱动程序列表中选取”-“网络适配器”-厂商Microsoft-“远程NDIS兼容设备”),设备管理和网络适配器中显示如下图
连接成功后,查看树莓派的usb0设备会分配一个ip地址 169.254.x.x(每次开机都可能不同)
此时,window下也能查看到分配到相同网段的ip
到这里,树莓派网卡虚拟配置已经成功,两者能够彼此ping成功。
3、usb无线网卡
3.1、树莓派4b aarch64 Debian12
使用的系统信息 Linux raspberrypi 6.6.31+rpt-rpi-v8 。外接ac1200(RTL8812AU)usb无线网卡,lsusb
能看到网卡信息,但是ifconfig
和 ip addr
看不到有新增的wlan1信息。
安装驱动
pi@raspberrypi:~ $ git clone -b v5.2.20 https://github/svpcom/rtl8812au.git
pi@raspberrypi:~ $ cd rtl8812au/
pi@raspberrypi:~/rtl8812au $ sudo ./dkms-install.sh
About to run dkms install steps...
Deprecated feature: REMAKE_INITRD (/usr/src/rtl8812au-5.2.20.2/dkms.conf)
Creating symlink /var/lib/dkms/rtl8812au/5.2.20.2/source -> /usr/src/rtl8812au-5.2.20.2
Sign command: /lib/modules/6.6.31+rpt-rpi-v8/build/scripts/sign-file
Signing key: /var/lib/dkms/mok.key
Public certificate (MOK): /var/lib/dkms/mok.pub
Certificate or key are missing, generating self signed certificate for MOK...
Deprecated feature: REMAKE_INITRD (/var/lib/dkms/rtl8812au/5.2.20.2/source/dkms.conf)
Building module:
Cleaning build area...
'make' -j4 KVER=6.6.31+rpt-rpi-v8 KSRC=/lib/modules/6.6.31+rpt-rpi-v8/build...................................................................
Signing module /var/lib/dkms/rtl8812au/5.2.20.2/build/88XXau_wfb.ko
Cleaning build area...
Deprecated feature: REMAKE_INITRD (/var/lib/dkms/rtl8812au/5.2.20.2/source/dkms.conf)
88XXau_wfb.ko.xz:
Running module version sanity check.
- Original module
- No original module exists within this kernel
- Installation
- Installing to /lib/modules/6.6.31+rpt-rpi-v8/updates/dkms/
depmod....
Finished running dkms install steps.
Disabled IPv6 Successfuly
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
安装成功,重启后查看,正常。
pi@raspberrypi:~ $ ip addr | grep wlan
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
inet 192.168.3.95/24 brd 192.168.3.255 scope global dynamic noprefixroute wlan0
4: wlan1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 4052 qdisc mq state UP group default qlen 1000
inet 192.168.3.6/24 brd 192.168.3.255 scope global dynamic noprefixroute wlan1
3.2、ubuntu18.04 接入 rtl8811c无线网卡
树莓派安装 ubuntu 18.04 插上之后 使用 dmesg 能够看到 NIC 无线网卡设备,但是ipconfig都就看不到(,并且无线网卡上的信号灯未闪烁)。可以确认是没有驱动。 使用的是rtl8811c系列,直接下载源码安装即可,如下
git clone https://github/brektrou/rtl8821CU.git
cd rtl8821CU
make -j4
make install
之后,重启,新增了一个wlan1接口。
注意,重启后两个无线网卡的名称可能出现调换,即重启后wlan0和wlan1可能对应的是不用网卡设备。
3.3、禁用某个无线网卡
前面可能会出现网卡名称对应设备出现变化的情况,如果要使用特定网卡设备,可以禁用其他网卡驱动。
-
1、使用
lshw -C network
查看网络设备信息ubuntu@ubuntu:~/Downloads/rtl8821CU$ sudo lshw -C network *-network:0 description: Wireless interface physical id: 1 bus info: usb@1:1.1 logical name: wlan0 serial: 90:de:80:a7:4d:50 capabilities: ethernet physical wireless configuration: broadcast=yes driver=rtl8821cu ip=192.168.3.59 multicast=yes wireless=IEEE 802.11AC *-network:1 description: Ethernet interface physical id: 2 logical name: eth0 serial: dc:a6:32:fb:fe:c4 size: 100Mbit/s capacity: 1Gbit/s capabilities: ethernet physical tp mii 10bt 10bt-fd 100bt 100bt-fd 1000bt 1000bt-fd autonegotiation configuration: autonegotiation=on broadcast=yes driver=bcmgenet driverversion=v2.0 duplex=full ip=192.168.3.39 link=yes multicast=yes port=MII speed=100Mbit/s *-network:2 description: Wireless interface physical id: 3 logical name: wlan1 serial: dc:a6:32:fb:fe:c5 capabilities: ethernet physical wireless configuration: broadcast=yes driver=brcmfmac driverversion=7.45.202 firmware=01-72f6ece2 ip=192.168.3.29 multicast=yes wireless=IEEE 802.11
可以看到我们的usb网卡使用 驱动为 rtl8821cu,树莓派网卡驱动为brcmfmac。
-
2、在
/etc/modprobe.d/blacklist.conf
屏蔽指定模块
例如,我们屏蔽树莓派网卡,则需要将树莓派网卡驱动加入到黑名单,禁止系统加载该驱动
在配置文件末尾添加blacklist brcmfmac
,之后重启即可。
恢复使用时,删除新增的行,重启。
3.4、监听模式
3.4.1、检查是否支持监听
首先查看无线网卡是否支持开启混杂功能,实现对所有数据包的监听能力。
使用 iw list
查看 ,在 Supported interface modes 中出现 monitor即说明支持。
可以使用 iwconfig
看到 wlan1 默认工作在 Managed 模式
pi@raspberrypi:~/projects/pcap_uav $ iwconfig
lo no wireless extensions.
eth0 no wireless extensions.
wlan0 IEEE 802.11 ESSID:"702-office"
Mode:Managed Frequency:5.18 GHz Access Point: C2:FC:A9:EF:80:15
Bit Rate=24 Mb/s Tx-Power=31 dBm
Retry short limit:7 RTS thr:off Fragment thr:off
Power Management:on
Link Quality=64/70 Signal level=-46 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0
wlan1 IEEE 802.11 ESSID:off/any
Mode:Managed Access Point: Not-Associated Tx-Power=18 dBm
Retry short limit:7 RTS thr:off Fragment thr:off
Power Management:off
3.4.2、开启监听
使用 iwconfig wlan1 mode monitor
命令行开启网卡wlan1 的监听模式。 若无该工具,安装 apt install wireless-tools
。
无任何错误则说明配置成功,否则说明不支持。如下图,
也可以使用 Aircrack-ng 套件 中的airmon-ng 来配置 airmon-ng start wlan1
pi@raspberrypi:~/projects/pcap_uav $ sudo airmon-ng start wlan1
Found 4 processes that could cause trouble.
Kill them using 'airmon-ng check kill' before putting
the card in monitor mode, they will interfere by changing channels
and sometimes putting the interface back in managed mode
PID Name
537 avahi-daemon
552 avahi-daemon
634 NetworkManager
645 wpa_supplicant
PHY Interface Driver Chipset
phy0 wlan0 brcmfmac Broadcom 43430
phy1 wlan1 rtl88xxau_wfb Realtek Semiconductor Corp. RTL8812AU 802.11a/b/g/n/ac 2T2R DB WLAN Adapter
(monitor mode enabled)
其中有提示影响开启监听模式,需要执行 airmon-ng check kill
后再次开启。
再次iwconfig查看其工作模式,确认工作在monitor模式
wlan1 IEEE 802.11 Mode:Monitor Frequency:2.457 GHz Tx-Power=18 dBm
Retry short limit:7 RTS thr:off Fragment thr:off
Power Management:off
4、静态ip配置
上一章中,树莓派作为usb网卡插入电脑后,树莓派本机会分配为169.254.x.x网段的随机ip。如果通过PC连接访问树莓派,就会存在问题。因此,期望固定树莓派的ip地址。
在 /etc/network/interfaces.d
中新增文件 usb0
,内容如下
auto usb0
allow-hotplug usb0
iface usb0 inet static
address 192.168.112.100
netmask 255.255.255.0
重启后,树莓派和pc端看到ip如下,树莓派静态ip配置成功,但是pc端仍然为169.254.x.x/16网段。
此时,windows pc端无法ping通树莓派。接着,在windows pc上配置网卡IP为树莓派相同网段,例如 ip为192.168.112.101,掩码为255.255.255.0,再次ping即可成功,如图
5、dhcp服务
在前一章的基础上,希望树莓派作为网卡接入pc时,pc能自动分配一个相同网段的ip。因此,配置一个dhcp服务。
- 保留
/etc/network/interfaces
中 usb0 的静态 ip 配置 - 安装 dnsmasq 服务
sudo apt-get install dnsmasq
- 在
/etc//etc/dnsmasq.conf
文件增加以下内容listen-address=192.168.112.100 interface=usb0 bind-interfaces dhcp-range=192.168.112.101,192.168.112.200, 255.255.255.0, 2h dhcp-option=3 dhcp-option=6 dhcp-authoritative
配置完成后,pc将自动分配 ip池 192.168.112.101~200的地址,网关为192.168.112.100,网关为192.168.112.100,掩码为 255.255.255.0。
重启树莓派,连接到pc上之后,pc自动获取了ip为192.168.112.101。
版权声明:本文标题:树莓派cm4 ioboard配置虚拟网卡、usb无线网卡、静态ip、dhcp服务 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1727799213a1130628.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论