bob*_*mac 4 ethernet networkmanager raspberry-pi usb-otg
我有一台计算机通过 DHCP 连接到路由器并且处于完全工作状态,我在仅链接模式下添加树莓派零时遇到问题。首先,我可以通过将连接从 DHCP 编辑为仅链接来连接 pi,但随后我显然失去了互联网,因为我一次只能连接一个有线设备,而且它们不像我的主以太网连接那样 DHCP。然后我虽然添加一个带有仅链接集的新连接将是一项简单的工作,我可以用它来连接pi,同时保持我的互联网完好无损,这是问题开始的地方我能够建立连接但由于某种原因无法让它将自己分配给 pi,我收到两个不同的消息,一个是activation of network connection failed
,另一个是Unable to find a connection with UUID ('null')
。
我搜索了互联网,但在我运行的nmcli c show
其中一个帖子中没有找到太多 sugested,它返回一个连接列表,这里新连接似乎都有一个 UUID。我被这个问题困住了,希望得到任何帮助。
nmcli
为通过在 OTG 模式下运行的 USB 端口连接到主机 PC 的 Raspberry Pi设置网络。我通过nmcli
命令行界面使用网络管理器成功地将桥接网络设置到 Raspberry Pi Zero 。
我按照上面评论中列出的这些说明为 OTG 以太网连接设置了 Pi。
修改 Pi 的 MiniSD 卡的文件系统
将以下内容添加到 SD 卡的 /boot/config.txt
# Enable USB OTG like ethernet
dtoverlay=dwc2
Run Code Online (Sandbox Code Playgroud)
ssh
在 SD 卡的/boot
目录中创建一个名为的空文件
touch ssh
Run Code Online (Sandbox Code Playgroud)
并通过将以下内容添加到 SD 卡的/boot/cmdline.txt
after将 OTG 以太网模块附加到引导加载程序rootwait
` modules-load=dwc2,g_ether `
Run Code Online (Sandbox Code Playgroud)
然后我在我的 PC 的有线以太网端口上设置了一个桥接网络接口。
nmcli con add type bridge ifname br0
nmcli con modify bridge-br0 bridge.stp no
nmcli con add type bridge-slave ifname eth1 master bridge-br0
Run Code Online (Sandbox Code Playgroud)
使用 Pi 上的 OTG 端口将 Raspberry Pi Zero 插入 PC。使用检查接口名称ifconfig.
然后将OTG接口添加到网桥。
nmcli con add type bridge-slave ifname enp0s29f7u1u4u3 master bridge-br0
Run Code Online (Sandbox Code Playgroud)
一切就绪后,我启用了连接:
nmcli con up bridge-br0
nmcli con up bridge-slave-eth1
nmcli con up bridge-slave-enp0s29f7u1u4u3
Run Code Online (Sandbox Code Playgroud)
用绿色验证所有接口 nmcli connection
root@local:/etc/ssh# nmcli con
NAME UUID TYPE DEVICE
bridge-br0 ab1fab48-2c31-4ccc-90bf-db444751c080 bridge br0
bridge-slave-enp0s29f7u1u4u3 5efed614-89c7-48d4-996e-0a2e6e616846 802-3-ethernet enp0s29f7u1u4u3
bridge-slave-eth1 53c4d66a-3f9e-49f4-b954-92b13ecf96f8 802-3-ethernet eth1
Run Code Online (Sandbox Code Playgroud)
然后查看我的 DHCP 服务器以进行 Raspberry Pi 网络地址分配。在您的配置中,该信息可通过您的路由器获得。SSH 到 Pi 成功:
root@local:/etc/ssh# ssh pi@192.168.xxx.xxx
pi@192.168.xxx.xxx's password:
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Wed Nov 1 19:33:48 2017 from 192.168.xxx.xxx
pi@raspberrypi:~ $ uname -a
Linux raspberrypi 4.4.38+ #938 Thu Dec 15 15:17:54 GMT 2016 armv6l GNU/Linux
pi@raspberrypi:~ $ ifconfig
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:724 errors:0 dropped:0 overruns:0 frame:0
TX packets:724 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:58980 (57.5 KiB) TX bytes:58980 (57.5 KiB)
usb0 Link encap:Ethernet HWaddr 8e:31:5b:06:db:bb
inet addr:192.168.xxx.xxx Bcast:192.168.xxx.xxx Mask:255.255.255.0
inet6 addr: fe80::xxx:/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:756 errors:0 dropped:0 overruns:0 frame:0
TX packets:430 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:90941 (88.8 KiB) TX bytes:76278 (74.4 KiB)
pi@raspberrypi:~ $ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.xxx.xxx 0.0.0.0 UG 202 0 0 usb0
192.168.xxx.0 * 255.255.255.0 U 202 0 0 usb0
pi@raspberrypi:~ $ sudo -s
root@raspberrypi:/home/pi# ping unix.stackexchange.com
PING unix.stackexchange.com (151.101.65.69) 56(84) bytes of data.
64 bytes from 151.101.65.69: icmp_seq=1 ttl=55 time=27.2 ms
64 bytes from 151.101.65.69: icmp_seq=2 ttl=55 time=7.91 ms
64 bytes from 151.101.65.69: icmp_seq=3 ttl=55 time=6.40 ms
64 bytes from 151.101.65.69: icmp_seq=4 ttl=55 time=6.78 ms
64 bytes from 151.101.65.69: icmp_seq=5 ttl=55 time=7.87 ms
^C
--- unix.stackexchange.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4006ms
rtt min/avg/max/mdev = 6.404/11.240/27.219/8.012 ms
root@raspberrypi:/home/pi#
Run Code Online (Sandbox Code Playgroud)
在阅读了 Pi OTG Networking 说明的第 2 部分后,我将添加他们提供的组件来永久设置 Pi 的 MAC 地址。使用永久 MAC 地址,您的 DHCP 服务器和/或路由器将在每次重启 RPi 时停止提供连续的 IP 地址。
webonomics 说:
您可以通过将这个附加到 cmdline.txt 中来完成此操作,该文件位于 pi 上的引导分区上:
g_ether.host_addr=8a:3e:d4:ce:89:53
建立连接后,只需从笔记本电脑的 ifconfig 命令中获取地址即可。
他们继续提到将 Pi 的配置从 DHCP 更改为静态 IP。但是,我不建议这样做。我总是建议在您网络的 DHCP 服务器上设置静态租约。这样,只需修改 DHCP 服务器即可重新设计网络。还有一些有用的方法可以划分子网,以限制其他主机对某些主机的访问。
大多数现代家庭路由器允许设置静态租约。利用 DHCP 服务器的全部功能是一种很好的做法。
我发现设置 g_ether.host_addr 不足以为 Pi 提供恒定的 MAC 地址。设置 g_ether.dev_addr 还有第二个要求
该小工具文件建议还设置一个制造商,以及产品编号。
Linux-USB 小工具 API 框架说:
为了更好地支持 DHCP、ZCIP 和相关的网络自动配置,您需要管理以太网地址,以便每个外设在每次启动时都重用相同的唯一地址。您应该使用注册的 IEEE 802 公司 ID 分配这些地址;这也将使设备在 Linux 主机上显示为“ethN”接口,而不是“usbN”。如果您使用 U-Boot 等引导固件,则无需单独的 ID PROM(或 initrd)即可轻松完成此操作:
*#* manufacturing assigns Ethernet addresses; company id is xx:xx:xx
setenv eth_a_host xx:xx:xx:01:23:45
setenv eth_a_gadget xx:xx:xx:67:89:ac
setenv eth_i_vendor "Great Stuff, LLC"
setenv eth_i_product "Our Cool Thing"
setenv eth_args g_ether.host_addr=\$(eth_a_host)
setenv eth_args $(eth_args) g_ether.dev_addr=\$(eth_a_gadget)
setenv eth_args $(eth_args) g_ether.iManufacturer=\$(eth_i_vendor)
setenv eth_args $(eth_args) g_ether.iProduct=\$(eth_i_product)
*#* you can assign USB vendor/product/version codes too...
setenv add_eth_args setenv bootargs $(eth_args) \$(bootargs)
...
setenv bootcmd run add_eth_args\;bootm
Run Code Online (Sandbox Code Playgroud)
这些参数也可以附加到cmdline.txt
DHCP 服务器的更好的可用性。