我已使用以太网将运行 Ubuntu 20.04 的 Raspberry Pi 连接到 Windows 笔记本电脑。我在 Windows 笔记本电脑上设置了以太网端口的静态 IP 和子网掩码,如下所示:
我已经在 Windows 笔记本电脑上启用了 Internet 共享:
我也在我的树莓派上设置了静态 IP:
# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.137.50 netmask 255.255.255.0 broadcast 192.168.137.255
ether 18:9b:a5:40:5d:59 txqueuelen 1000 (Ethernet)
RX packets 203 bytes 22521 (22.5 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 234 bytes 12036 (12.0 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
我能够从 Raspberry pi ping Windows 笔记本电脑:
# ping 192.168.137.1
PING 192.168.137.1 (192.168.137.1): 56 data bytes
64 bytes from 192.168.137.1: icmp_seq=0 ttl=128 time=2.061 ms
64 bytes from 192.168.137.1: icmp_seq=1 ttl=128 time=5.545 ms
64 bytes from 192.168.137.1: icmp_seq=2 ttl=128 time=1.805 ms
^C--- 192.168.137.1 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max/stddev = 1.805/3.137/5.545/1.706 ms
另外,我可以从 Windows 笔记本电脑 ping Raspberry Pi:
>ping 192.168.137.50
Pinging 192.168.137.50 with 32 bytes of data:
Reply from 192.168.137.50: bytes=32 time=4ms TTL=64
Reply from 192.168.137.50: bytes=32 time=3ms TTL=64
Reply from 192.168.137.50: bytes=32 time=1ms TTL=64
Ping statistics for 192.168.137.50:
Packets: Sent = 3, Received = 3, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 1ms, Maximum = 4ms, Average = 2ms
我能够从 Windows 笔记本电脑 ping 谷歌:
>ping google.com
Pinging google.com [172.217.166.46] with 32 bytes of data:
Reply from 172.217.166.46: bytes=32 time=31ms TTL=58
Reply from 172.217.166.46: bytes=32 time=14ms TTL=58
Reply from 172.217.166.46: bytes=32 time=20ms TTL=58
Ping statistics for 172.217.166.46:
Packets: Sent = 3, Received = 3, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 14ms, Maximum = 31ms, Average = 21ms
但我无法从树莓派 ping 通谷歌:
# ping google.com
PING google.com (172.217.166.46): 56 data bytes
^C92 bytes from 192.168.137.50: Destination Host Unreachable
--- google.com ping statistics ---
4 packets transmitted, 0 packets received, 100% packet loss
我在这里遗漏了什么?
附言:
以下是一些可能有用的命令的输出:
# cat /etc/resolv.conf
# Generated by resolvconf
domain mshome.net
nameserver 127.0.0.1
# route -ne
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 0.0.0.0 0.0.0.0 U 0 0 0 eth0
0.0.0.0 192.168.137.1 0.0.0.0 UG 0 0 0 eth0
192.168.137.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.225.0 0.0.0.0 255.255.255.0 U 0 0 0 bridge0