![如何将我的 eth 有线互联网从我的电脑共享到我的 eth 有线树莓派(非 WiFi)](https://linux22.com/image/228837/%E5%A6%82%E4%BD%95%E5%B0%86%E6%88%91%E7%9A%84%20eth%20%E6%9C%89%E7%BA%BF%E4%BA%92%E8%81%94%E7%BD%91%E4%BB%8E%E6%88%91%E7%9A%84%E7%94%B5%E8%84%91%E5%85%B1%E4%BA%AB%E5%88%B0%E6%88%91%E7%9A%84%20eth%20%E6%9C%89%E7%BA%BF%E6%A0%91%E8%8E%93%E6%B4%BE%EF%BC%88%E9%9D%9E%20WiFi%EF%BC%89.png)
我有一台 PC 和 RPI,都运行 Debian。
我的 PC 通过以太网(不是 WiFi)访问互联网,并且我通过另一个以太网从 PC 到 RPI 使用 ssh 连接到我的 RPI。
PC 到 RPI 连接使用静态 IP 设置/etc/网络/接口
但是,我无法在树莓派上访问互联网
如何让我的 rpi 通过我的电脑共享互联网?
我已保证猫 /proc/sys/net/ipv4/ip_forward显示1
尝试更新 iptables
iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE
我还尝试了许多其他 iptables 命令,并进行了大约 5 个小时的反复试验,但似乎没有任何效果,我已从 iptables 数据库中删除了所有失败的 iptables 更新以避免出现问题。
我的电脑/etc/网络/接口
#ethernet internet into pc
auto eth0
allow-hotplug eth0
iface eth0 inet dhcp
iface eth0 inet6 dhcp
request_prefix 1
#eth1 = eth-usb adapter to connect to rpi
auto eth1
allow-hotplug eth1
iface eth1 inet static
address 192.168.0.101/24
我的零售价格指数/etc/网络/接口
auto eth0
allow-hotplug eth0
iface eth0 inet static
address 192.168.0.100/24
dns-nameservers 192.168.0.101
用于故障排除的网络输出。
电脑命令知识产权
default via 192.168.6.1 dev eth0 proto dhcp metric 100
169.254.0.0/16 dev eth1 scope link metric 1000
[IP MASKED] via 192.168.6.1 dev eth0 proto static metric 100
192.168.0.0/24 dev eth1 proto kernel scope link src 192.168.0.101
192.168.6.0/24 dev eth0 proto kernel scope link src 192.168.6.169 metric 100
192.168.6.1 dev eth0 proto static scope link metric 100
RPI命令知识产权
default via 192.168.0.101 dev eth0 online
192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.100
指令ip规则在 PC 和 RPI 上均输出
0: from all lookup local
32766: from all lookup main
32767: from all lookup default
在PC上cmdsudo iptables-保存-c
# Generated by iptables-save v1.8.7 on Sun Feb 4 13:58:41 2024
*mangle
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [342:36803]
COMMIT
# Completed on Sun Feb 4 13:58:41 2024
# Generated by iptables-save v1.8.7 on Sun Feb 4 13:58:41 2024
*filter
:INPUT ACCEPT [168:27052]
:FORWARD ACCEPT [70:6256]
:OUTPUT ACCEPT [0:0]
COMMIT
# Completed on Sun Feb 4 13:58:41 2024
# Generated by iptables-save v1.8.7 on Sun Feb 4 13:58:41 2024
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [66:5191]
COMMIT
# Completed on Sun Feb 4 13:58:41 2024
电脑命令sudo iptables -t nat -L -n -v
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain POSTROUTING (policy ACCEPT 255 packets, 38565 bytes)
pkts bytes target prot opt in out source destination