每次我将我的Raspberry Pi连接到我的计算机的USB端口时,我总是需要将创建到我的Linux计算机的连接设置为共享。我是通过网络管理器来做这件事的,就像屏幕截图(UI中的希腊语):

这有点乏味,每次花费2-3分钟来设置共享连接,以便在其中使用ssh。因此,我希望一旦设备插入共享连接后自动创建,因此,我不需要每次将raspberry pi插入USB端口时通过网络管理器配置网络接口。
有办法这样做吗。到目前为止,一旦输入lsusb,就会得到以下结果:
$ lsusb
Bus 002 Device 002: ID 05e3:0732 Genesys Logic, Inc. All-in-One Cardreader
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 1a40:0101 Terminus Technology Inc. Hub
Bus 001 Device 002: ID 4e53:5407
Bus 001 Device 010: ID 0925:3881 Lakeview Research Saleae Logic
Bus 001 Device 009: ID 0525:a4a2 Netchip Technology, Inc. Linux-USB Ethernet/RNDIS Gadget
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub当我插件USB时创建的设备是:
Bus 001 Device 009: ID 0525:a4a2 Netchip Technology, Inc. Linux-USB Ethernet/RNDIS Gadget一。
dmesg还显示了以下内容:
[ 2015.792407] usb 1-3: new full-speed USB device number 8 using xhci_hcd
[ 2016.368398] usb 1-3: new high-speed USB device number 9 using xhci_hcd
[ 2016.517429] usb 1-3: New USB device found, idVendor=0525, idProduct=a4a2, bcdDevice= 5.10
[ 2016.517434] usb 1-3: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 2016.517437] usb 1-3: Product: RNDIS/Ethernet Gadget
[ 2016.517441] usb 1-3: Manufacturer: Linux 5.10.63+ with 20980000.usb
[ 2016.518553] cdc_subset: probe of 1-3:1.0 failed with error -22
[ 2016.520510] cdc_ether 1-3:1.0 usb0: register 'cdc_ether' at usb-0000:00:14.0-3, CDC Ethernet Device, 12:e2:73:0a:fa:92
[ 2016.550226] cdc_ether 1-3:1.0 enp0s20f0u3: renamed from usb0
[ 2017.365925] [UFW BLOCK] IN=br-c2a79e951b81 OUT= MAC= SRC=fe80:0000:0000:0000:0042:f4ff:fe99:0011 DST=ff02:0000:0000:0000:0000:0000:0000:0001 LEN=89 TC=0 HOPLIMIT=1 FLOWLBL=617835 PROTO=UDP SPT=22161 DPT=161 LEN=49
[ 2017.532279] [UFW BLOCK] IN=br-c2a79e951b81 OUT= MAC= SRC=fe80:0000:0000:0000:0042:f4ff:fe99:0011 DST=ff02:0000:0000:0000:0000:0000:0000:0001 LEN=89 TC=0 HOPLIMIT=1 FLOWLBL=617835 PROTO=UDP SPT=22161 DPT=161 LEN=49
[ 2042.958713] IPv6: ADDRCONF(NETDEV_CHANGE): enp0s20f0u3: link becomes ready
[ 2216.944793] audit: type=1400 audit(1644678209.643:133): apparmor="DENIED" operation="capable" profile="/snap/snapd/14549/usr/lib/snapd/snap-confine" pid=10514 comm="snap-confine" capability=4 capname="fsetid"
[ 2220.764823] audit: type=1326 audit(1644678213.463:134): auid=4294967295 uid=1000 gid=1000 ses=4294967295 pid=10514 comm="telegram-deskto" exe="/snap/telegram-desktop/3544/usr/bin/telegram-desktop" sig=0 arch=c000003e syscall=314 compat=0 ip=0x7f353fbdc89d code=0x50000
[ 2223.187662] audit: type=1400 audit(1644678215.883:135): apparmor="DENIED" operation="open" profile="snap.telegram-desktop.telegram-desktop" name="/etc/openal/alsoft.conf" pid=10514 comm="telegram-deskto" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
[ 2224.579172] audit: type=1326 audit(1644678217.275:136): auid=4294967295 uid=1000 gid=1000 ses=4294967295 pid=10514 comm="telegram-deskto" exe="/snap/telegram-desktop/3544/usr/bin/telegram-desktop" sig=0 arch=c000003e syscall=203 compat=0 ip=0x7f3541bb26e1 code=0x50000
[ 2224.579181] audit: type=1326 audit(1644678217.275:137): auid=4294967295 uid=1000 gid=1000 ses=4294967295 pid=10514 comm="telegram-deskto" exe="/snap/telegram-desktop/3544/usr/bin/telegram-desktop" sig=0 arch=c000003e syscall=141 compat=0 ip=0x7f353fbd834b code=0x50000
[ 2224.579187] audit: type=1326 audit(1644678217.275:138): auid=4294967295 uid=1000 gid=1000 ses=4294967295 pid=10514 comm="telegram-deskto" exe="/snap/telegram-desktop/3544/usr/bin/telegram-desktop" sig=0 arch=c000003e syscall=203 compat=0 ip=0x7f3541bb26e1 code=0x50000
[ 2224.579224] audit: type=1326 audit(1644678217.275:139): auid=4294967295 uid=1000 gid=1000 ses=4294967295 pid=10514 comm="telegram-deskto" exe="/snap/telegram-desktop/3544/usr/bin/telegram-desktop" sig=0 arch=c000003e syscall=141 compat=0 ip=0x7f353fbd834b code=0x50000
[ 2224.579342] audit: type=1326 audit(1644678217.275:140): auid=4294967295 uid=1000 gid=1000 ses=4294967295 pid=10514 comm="telegram-deskto" exe="/snap/telegram-desktop/3544/usr/bin/telegram-desktop" sig=0 arch=c000003e syscall=203 compat=0 ip=0x7f3541bb26e1 code=0x50000
[ 2224.579352] audit: type=1326 audit(1644678217.275:141): auid=4294967295 uid=1000 gid=1000 ses=4294967295 pid=10514 comm="telegram-deskto" exe="/snap/telegram-desktop/3544/usr/bin/telegram-desktop" sig=0 arch=c000003e syscall=141 compat=0 ip=0x7f353fbd834b code=0x50000
[ 2224.579507] audit: type=1326 audit(1644678217.275:142): auid=4294967295 uid=1000 gid=1000 ses=4294967295 pid=10514 comm="telegram-deskto" exe="/snap/telegram-desktop/3544/usr/bin/telegram-desktop" sig=0 arch=c000003e syscall=203 compat=0 ip=0x7f3541bb26e1 code=0x50000
[ 2224.579515] audit: type=1326 audit(1644678217.275:143): auid=4294967295 uid=1000 gid=1000 ses=4294967295 pid=10514 comm="telegram-deskto" exe="/snap/telegram-desktop/3544/usr/bin/telegram-desktop" sig=0 arch=c000003e syscall=203 compat=0 ip=0x7f3541bb26e1 code=0x50000
[ 2224.579551] audit: type=1326 audit(1644678217.275:144): auid=4294967295 uid=1000 gid=1000 ses=4294967295 pid=10514 comm="telegram-deskto" exe="/snap/telegram-desktop/3544/usr/bin/telegram-desktop" sig=0 arch=c000003e syscall=203 compat=0 ip=0x7f3541bb26e1 code=0x50000
[ 3121.350145] usb 1-5: new high-speed USB device number 10 using xhci_hcd
[ 3121.498265] usb 1-5: New USB device found, idVendor=0925, idProduct=3881, bcdDevice= 0.01
[ 3121.498271] usb 1-5: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[ 3122.347647] [UFW BLOCK] IN=br-c2a79e951b81 OUT= MAC= SRC=fe80:0000:0000:0000:0042:f4ff:fe99:0011 DST=ff02:0000:0000:0000:0000:0000:0000:0001 LEN=89 TC=0 HOPLIMIT=1 FLOWLBL=617835 PROTO=UDP SPT=22161 DPT=161 LEN=49
[ 3122.513998] [UFW BLOCK] IN=br-c2a79e951b81 OUT= MAC= SRC=fe80:0000:0000:0000:0042:f4ff:fe99:0011 DST=ff02:0000:0000:0000:0000:0000:0000:0001 LEN=89 TC=0 HOPLIMIT=1 FLOWLBL=617835 PROTO=UDP SPT=22161 DPT=161 LEN=49
[ 3122.680261] [UFW BLOCK] IN=br-c2a79e951b81 OUT= MAC= SRC=fe80:0000:0000:0000:0042:f4ff:fe99:0011 DST=ff02:0000:0000:0000:0000:0000:0000:0001 LEN=89 TC=0 HOPLIMIT=1 FLOWLBL=617835 PROTO=UDP SPT=22161 DPT=161 LEN=49
[ 3122.880905] [UFW BLOCK] IN=enp3s0 OUT= MAC= SRC=fe80:0000:0000:0000:1be3:4633:095f:d015 DST=ff02:0000:0000:0000:0000:0000:0000:0001 LEN=64 TC=0 HOPLIMIT=1 FLOWLBL=663885 PROTO=UDP SPT=8612 DPT=8612 LEN=24
[ 3122.880917] [UFW BLOCK] IN=enp3s0 OUT= MAC= SRC=fe80:0000:0000:0000:1be3:4633:095f:d015 DST=ff02:0000:0000:0000:0000:0000:0000:0001 LEN=64 TC=0 HOPLIMIT=1 FLOWLBL=837265 PROTO=UDP SPT=8612 DPT=8610 LEN=24
[ 3122.880928] [UFW BLOCK] IN=br-c2a79e951b81 OUT= MAC= SRC=fe80:0000:0000:0000:0042:f4ff:fe99:0011 DST=ff02:0000:0000:0000:0000:0000:0000:0001 LEN=64 TC=0 HOPLIMIT=1 FLOWLBL=255464 PROTO=UDP SPT=8612 DPT=8612 LEN=24
[ 3122.880938] [UFW BLOCK] IN=br-c2a79e951b81 OUT= MAC= SRC=fe80:0000:0000:0000:0042:f4ff:fe99:0011 DST=ff02:0000:0000:0000:0000:0000:0000:0001 LEN=64 TC=0 HOPLIMIT=1 FLOWLBL=341915 PROTO=UDP SPT=8612 DPT=8610 LEN=24
[ 3122.880946] [UFW BLOCK] IN=vethc930aa4 OUT= MAC= SRC=fe80:0000:0000:0000:0814:60ff:fee9:705f DST=ff02:0000:0000:0000:0000:0000:0000:0001 LEN=64 TC=0 HOPLIMIT=1 FLOWLBL=674828 PROTO=UDP SPT=8612 DPT=8612 LEN=24
[ 3122.880953] [UFW BLOCK] IN=vethc930aa4 OUT= MAC= SRC=fe80:0000:0000:0000:0814:60ff:fee9:705f DST=ff02:0000:0000:0000:0000:0000:0000:0001 LEN=64 TC=0 HOPLIMIT=1 FLOWLBL=1048135 PROTO=UDP SPT=8612 DPT=8610 LEN=24
[ 3122.880960] [UFW BLOCK] IN=enp0s20f0u3 OUT= MAC= SRC=fe80:0000:0000:0000:1eaf:0969:516b:39cb DST=ff02:0000:0000:0000:0000:0000:0000:0001 LEN=64 TC=0 HOPLIMIT=1 FLOWLBL=326809 PROTO=UDP SPT=8612 DPT=8612 LEN=24 我运行的发行版是Linux 19,我认为udev是我必须遵循的方法,但我不知道如何实现。
但是我想要的是,一旦我在Gadget模式下插件我的raspberry pi,将连接设置为
现在,我成功地设置了一个udev规则,以便给它取一个名称:
SUBSYSTEM=="net", ACTION=="add", ATTRS{idVendor}=="0525", ATTRS{idProduct}=="a4a2", NAME="rpi0"但是我所做的,我成功地将接口从usb0重命名为rpi0。但是,我无法确定如何向netowkr管理器指定插件接口的特定设置。
我想要的是,一旦我插件了raspberry pi,就不会试图通过创建文件/etc/NetworkManager/conf.d/rpi0.conf来自动连接
[main]
no-auto-default=rpi0但是,每次我尝试连接一个新的网络连接都会被创建。
有没有办法分享我的连接和绕过网络管理器作为一个整体?
发布于 2022-02-13 16:44:55
您必须通过udev规则来管理它,并且完全不允许网络nagagher来管理它。
最重要的是,您应该将网络设置临时设置为最后一次共享,并通过在/etc/dhcpcd.conf中添加以下设置将静态ip设置设置为raspberry pi:
interface usb0
static ip_address=10.42.0.62/24
static routers=10.42.0.1
static domain_name_servers=1.1.1.1但是,在您这样做之前,请确保usb0接口是由raspberry pi通过usb运行ifconfig连接时使用的接口。建议设置在ifconfig中看到的设置,因为它们相对安全。在我的例子中,ifconfig for usb0是:
usb0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.42.0.62 netmask 255.255.255.0 broadcast 10.42.0.255
inet6 fe80::2f8c:1871:13b2:dc30 prefixlen 64 scopeid 0x20<link>
ether ce:bb:5c:2b:f2:46 txqueuelen 1000 (Ethernet)
RX packets 230 bytes 19437 (18.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 891 bytes 56964 (55.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0。
您需要使用udev作为管理接口的一种方法。在我的例子中,我创建了一个名为/etc/udev/rules.d/99_rpi_net_renamer.rules的文件:
SUBSYSTEM=="net", ACTION=="add", ATTRS{idVendor}=="0525", ATTRS{idProduct}=="a4a2", NAME="rpi0", RUN+="/sbin/ifconfig rpi0 down", RUN+="/sbin/ifconfig rpi0 10.42.0.61/24 broadcast 10.42.0.255",RUN+="/sbin/ifconfig rpi0 up"我所做的是基于lsusb,我列出了所有的设备:
lsusb
Bus 002 Device 002: ID 05e3:0732 Genesys Logic, Inc. All-in-One Cardreader
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 1a40:0101 Terminus Technology Inc. Hub
Bus 001 Device 002: ID 4e53:5407
Bus 001 Device 010: ID 0925:3881 Lakeview Research Saleae Logic
Bus 001 Device 009: ID 0525:a4a2 Netchip Technology, Inc. Linux-USB Ethernet/RNDIS Gadget
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub为了找到raspberry pi,我将其插入并从usb端口中拔出,同时通过一次又一次地运行它来比较lsusb的各种输出。就我而言,这个装置是:
Bus 001 Device 009: ID 0525:a4a2 Netchip Technology, Inc. Linux-USB Ethernet/RNDIS Gadget因此,在udev规则中,我放置了一个记录:
SUBSYSTEM=="net", ACTION=="add", ATTRS{idVendor}=="XXXX", ATTRS{idProduct}=="YYY", NAME="rpi0", RUN+="/sbin/ifconfig rpi0 down", RUN+="/sbin/ifconfig rpi0 10.42.0.61/24 broadcast 10.42.0.255",RUN+="/sbin/ifconfig rpi0 up"XXXX为0525,YYYY为a4a2。作为lsusb中的一条经验规则,您应该以以下格式查找记录:
Bus 001 Device 009: ID XXXX:YYYY Netchip Technology, Inc. Linux-USB Ethernet/RNDIS GadgetXXXX和YYYY分别是ATTRS{idVendor}和ATTRS{idProduct}。
的管理
在我的例子中,我在/etc/NetworkManager/conf.d/rpi0.conf中放置了以下规则:
[main]
no-auto-default=rpi0
[keyfile]
unmanaged-devices=rpi0为了应用这些更改,运行:
sudo udevadm control --reload-rules && sudo udevadm trigger
sudo service network manager restart然后,拔下插头,再次插入Raspberry Pi,以查看更改是否有效。
https://unix.stackexchange.com/questions/690381
复制相似问题