通过以太网与 Raspberry Pi 共享台式机的 WiFi 互联网

通过以太网与 Raspberry Pi 共享台式机的 WiFi 互联网

我正在尝试在无头模式下设置我的 RPi,但在通过以太网共享我的 Ubuntu 桌面的 WiFi 互联网时遇到了问题。这个问题确实之前有人问过,但出于某种原因,它们对我来说不起作用。

注意:RPi 确实有 WiFi,我可以使用 VNC Viewer 通过桌面进行设置。但是...我正在尝试了解有关网络的更多信息,因此非常感谢任何帮助!

标准解决方案是使用nm-connection-editor,打开有线连接IPv4 设置并改变方法共享至其他计算机.例如此解决方案但考虑到我使用的是 22.04LTS。不幸的是,它不能“正常工作”。

我可以使用 ssh 进入 RPi raspberrypi.local,以下是未启用 WiFi 时其互联网信息:

pi@raspberrypi:~ $ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether d8:3a:dd:02:9d:80 brd ff:ff:ff:ff:ff:ff
    inet 10.42.0.159/24 brd 10.42.0.255 scope global dynamic noprefixroute eth0
       valid_lft 3496sec preferred_lft 3046sec
    inet6 fe80::bd30:6f44:d39b:756e/64 scope link 
       valid_lft forever preferred_lft forever
3: wlan0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
    link/ether d8:3a:dd:02:9d:81 brd ff:ff:ff:ff:ff:ff

Ubuntu 桌面报告:

(base) ➜  ~ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp4s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 14:b3:1f:0d:d4:16 brd ff:ff:ff:ff:ff:ff
    inet 10.42.0.1/24 brd 10.42.0.255 scope global noprefixroute enp4s0
       valid_lft forever preferred_lft forever
    inet6 fe80::6b87:d248:300a:5cd7/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: wlp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 7c:67:a2:36:26:49 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.133/24 brd 192.168.0.255 scope global dynamic noprefixroute wlp3s0
       valid_lft 80608sec preferred_lft 80608sec
5: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:42:de:32:8f brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever

启用 WiFi 的 RPi 报告:

pi@raspberrypi:~ $ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether d8:3a:dd:02:9d:80 brd ff:ff:ff:ff:ff:ff
    inet 10.42.0.159/24 brd 10.42.0.255 scope global dynamic noprefixroute eth0
       valid_lft 3282sec preferred_lft 2832sec
    inet6 fe80::bd30:6f44:d39b:756e/64 scope link 
       valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether d8:3a:dd:02:9d:81 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.198/24 brd 192.168.0.255 scope global dynamic noprefixroute wlan0
       valid_lft 86398sec preferred_lft 75598sec
    inet6 2001:8003:d546:9800:3823:405f:2c2d:1475/64 scope global dynamic mngtmpaddr noprefixroute 
       valid_lft 44695sec preferred_lft 44695sec
    inet6 fe80::6dea:75b5:1713:2454/64 scope link 
       valid_lft forever preferred_lft forever

我可以看到,当 WiFi 开启时,我们有:

192.168.0.198/24 brd 192.168.0.255 scope global dynamic noprefixroute wlan0

但只有以太网,我们才能:

inet 10.42.0.159/24 brd 10.42.0.255 scope global dynamic noprefixroute eth0

因此,两者都具有相同scope和其他设置,但一个在我的家庭局域网上192.168.0.198,另一个在桌面的本地 IP 地址上:10.42.0.159

我看到有些指南建议设置静态 IP:这里这里, 和这里。但这只是为了寻址方便(对吧?)。

所以我很想知道我的台式机是怎么回事,这意味着它的互联网连接不是正在共享,即使已在有线连接 IPv4 设置中设置。还有其他我可以查看的诊断信息吗?

感谢您的任何帮助!

- - 编辑

在桌面上运行的另一个网络命令:

(base) ➜  ~ nmcli dev show enp4s0
GENERAL.DEVICE:                         enp4s0
GENERAL.TYPE:                           ethernet
GENERAL.HWADDR:                         14:B3:1F:0D:D4:16
GENERAL.MTU:                            1500
GENERAL.STATE:                          100 (connected)
GENERAL.CONNECTION:                     Wired connection 1
GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/ActiveConnection/12
WIRED-PROPERTIES.CARRIER:               on
IP4.ADDRESS[1]:                         10.42.0.1/24
IP4.GATEWAY:                            --
IP4.ROUTE[1]:                           dst = 10.42.0.0/24, nh = 0.0.0.0, mt = 100
IP6.ADDRESS[1]:                         fe80::6b87:d248:300a:5cd7/64
IP6.GATEWAY:                            --
IP6.ROUTE[1]:                           dst = fe80::/64, nh = ::, mt = 1024

相关内容