树莓派cm4 ioboard配置虚拟网卡、usb无线网卡、静态ip、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 能看到网卡信息,但是ifconfigip addr 看不到有新增的wlan1信息。

安装驱动

pi@raspberrypi:~ $ git clone -b v5.2.20 https://github.com/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.com/brektrou/rtl8821CU.git
cd rtl8821CU
make -j4
make install

之后,重启,新增了一个wlan1接口。
在这里插入图片描述
注意,重启后两个无线网卡的名称可能出现调换,即重启后wlan0和wlan1可能对应的是不用网卡设备。

其他操作命令

sudo iwconfig

sudo ip link set wlan1 down
sudo iwconfig wlan1 mode monitor
sudo ip link set wlan1 up

sudo ip link set wlan1 down
sudo iwconfig wlan1 mode managed
sudo ip link set wlan1 up

sudo iwconfig wlan1 channel 6

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 无法检测到有线网卡解决方案 对于树莓派 CM4 无法检测到有线网卡的情况,可能涉及硬件连接、驱动程序以及操作系统设置等多个方面。以下是详细的排查和解决办法: #### 1. 检查物理连接 确认有线网卡已正确插入并牢固固定于树莓派 CM4USB 或 PCIe 接口上。如果使用的是扩展板,则需进一步验证扩展板与 CM4 的连接稳固无误。 #### 2. 验证内核模块加载情况 通过命令行查看是否有对应的网络接口被识别,并检查相关内核模块是否已经自动加载。 ```bash lsmod | grep usbnet dmesg | grep eth ``` 上述命令用于查找是否存在 `usbnet` 类型的设备以及任何关于以太网 (`eth`) 设备的日志信息[^1]。 #### 3. 手动安装驱动程序 若发现缺少必要的驱动支持,可以尝试手动获取适用于特定型号有线网卡的 Linux 驱动源码包,并按照说明文档完成编译安装过程。注意选择兼容 ARM 架构版本的操作系统镜像文件来匹配树莓派平台特性[^2]。 #### 4. 更新固件与系统软件 保持系统的最新状态有助于获得更好的硬件兼容性和稳定性。执行以下更新指令: ```bash sudo apt-y sudo rpi-update reboot now ``` 这将确保所有可用的安全补丁和其他改进都被应用到了当前环境中[^3]。 #### 5. 修改配置文件 编辑 `/boot/config.txt` 文件,在其中添加或修改如下参数以便更好地适配某些类型的 NIC (Network Interface Controller): ```ini dtoverlay=lan78xx,dr_mode=9 ``` 保存更改后重启机器使新设定生效。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

aworkholic

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值