我的 Raspberry 3b 中有 Raspbian Jessie。我的测试实验是ping google.com
,是我学习网络时做的。我在 Raspberry 中的配置/etc/network/interfaces
基于此线但将lan-ip更改为192.169.1.0(也尝试过192.168.1.1)
iface eth0 inet static
address 192.168.1.0
netmask 255.255.255.0
gateway 192.168.1.254
broadcast 255.255.255.255
我的路由器设置(固件:DD-WRT v24-sp2 (01/04/15) std)
Router Model TPLINK WR1043ND V2
WAN IPv4 10.10.11.59
LAN IP 192.168.1.1
我ifconfig
在 Raspian 中看到了
eth0 Link encap:Ethernet HWaddr b8:27:eb:af:7b:89
inet addr:192.168.1.0 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::ba27:ebff:feaf:7b89/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:10 errors:0 dropped:0 overruns:0 frame:0
TX packets:58 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1851 (1.8 KiB) TX bytes:10287 (10.0 KiB)
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:304 errors:0 dropped:0 overruns:0 frame:0
TX packets:304 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:24096 (23.5 KiB) TX bytes:24096 (23.5 KiB)
wlan0 Link encap:Ethernet HWaddr b8:27:eb:fa:2e:dc
inet6 addr: fe80::ba27:ebff:fefa:2edc/64 Scope:Link
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:24 errors:0 dropped:24 overruns:0 frame:0
TX packets:22 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:11676 (11.4 KiB) TX bytes:4607 (4.4 KiB)
我也做了sudo ip link set dev eth1 down
,sudo dhclient eth1
但没有积极的结果。
经过 GAD3R 的提议
我完成了 GAD3R 的提案。我ifconfig
现在给予
eth0 Link encap:Ethernet HWaddr b8:27:eb:af:7b:89
inet addr:192.168.1.0 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::511d:2a5a:7049:4087/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:25 errors:0 dropped:0 overruns:0 frame:0
TX packets:216 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2298 (2.2 KiB) TX bytes:43352 (42.3 KiB)
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:856 errors:0 dropped:0 overruns:0 frame:0
TX packets:856 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:68368 (66.7 KiB) TX bytes:68368 (66.7 KiB)
wlan0 Link encap:Ethernet HWaddr b8:27:eb:fa:2e:dc
inet6 addr: fe80::ba27:ebff:fefa:2edc/64 Scope:Link
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:184 errors:0 dropped:184 overruns:0 frame:0
TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:92808 (90.6 KiB) TX bytes:3173 (3.0 KiB)
我做ping google.com
不成功。
GAD3R的添加
我将网关从 更改192.168.1.1
为192.168.0.1
。输出ifconfig
eth0 Link encap:Ethernet HWaddr b8:27:eb:af:7b:89
inet addr:192.168.1.0 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::511d:2a5a:7049:4087/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3 errors:0 dropped:0 overruns:0 frame:0
TX packets:114 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:712 (712.0 B) TX bytes:21781 (21.2 KiB)
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:384 errors:0 dropped:0 overruns:0 frame:0
TX packets:384 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:31104 (30.3 KiB) TX bytes:31104 (30.3 KiB)
wlan0 Link encap:Ethernet HWaddr b8:27:eb:fa:2e:dc
inet6 addr: fe80::ba27:ebff:fefa:2edc/64 Scope:Link
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:309 errors:0 dropped:309 overruns:0 frame:0
TX packets:22 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:158484 (154.7 KiB) TX bytes:4345 (4.2 KiB)
我做ping google.com
不成功。
DAP3R的第二次补充
我将地址从192.168.1.50
更改为192.168.0.50
并将广播从192.168.1.255
更改为192.168.0.255
。输出ifconfig
eth0 Link encap:Ethernet HWaddr b8:27:eb:af:7b:89
inet addr:192.168.1.0 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::511d:2a5a:7049:4087/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:6 errors:0 dropped:0 overruns:0 frame:0
TX packets:107 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:850 (850.0 B) TX bytes:21039 (20.5 KiB)
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:432 errors:0 dropped:0 overruns:0 frame:0
TX packets:432 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:34464 (33.6 KiB) TX bytes:34464 (33.6 KiB)
wlan0 Link encap:Ethernet HWaddr b8:27:eb:fa:2e:dc
inet6 addr: fe80::ba27:ebff:fefa:2edc/64 Scope:Link
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:217 errors:0 dropped:217 overruns:0 frame:0
TX packets:19 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:111112 (108.5 KiB) TX bytes:4094 (3.9 KiB)
我做ping google.com
不成功。
roiama 答案的输出
命令netstat -rn
给了我
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
而不是你的一行192.168.1.1.0...
.平
- ping 192.168.1.2 主机无法访问
- ping 192.168.1.1 大约需要 0.3 毫秒,因此在 <10 毫秒内
- ping 8.8.8.8 就像 8 毫秒,所以在 <30 毫秒内
- ping google.com 成功,耗时 8 毫秒
如何通过 Eth0 将 Raspbian 连接到互联网?
答案1
强烈建议您将静态配置转换为 DHCP,直到您的连接得到验证。 (您的配置中有几个错误,动态配置可以避免所有这些错误。)
iface eth0 inet dhcp
如果这不起作用,您需要在继续操作之前查看您的本地网络。
这就是您目前所拥有的:
iface eth0 inet static address 192.168.1.0 netmask 255.255.255.0 gateway 192.168.1.254 broadcast 255.255.255.255
24 位网络掩码的主机地址从 1 到 254。零和 255 被保留,因此您建议的地址是“非法的”。将其从 更改192.168.1.0
为192.168.1.2
。
您的路由器的 LAN 地址是192.168.1.1
您需要在此处声明为上游网关的地址。将其从 更改192.168.1.254
为192.168.1.1
。
广播地址必须属于局域网,而不是全世界。将其从 更改255.255.255.255
为192.168.1.255
。
现在重新启动界面(或重新启动您的 Pi)。您应该在网络表 ( netstat -rn
) 中看到两个条目,如下所示:
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
您还应该能够通过地址(但可能无法通过名称)对地点执行 ping 操作。尝试以下测试作为起点:
ping 192.168.1.2 # Should be <1ms response as this is you
ping 192.168.1.1 # Should be <10ms response as this is your router
ping 8.8.8.8 # Expect ~30ms response as this is a Google node on the Internet
当且仅当这一切都有效时,您才可以继续配置名称服务器,它将名称转换为 IP 地址。 (这些通常也可以通过 DHCP 分配。)将其配置为路由器的地址,或者如果必须的话,选择一个或两个上游服务器。创建/etc/resolv.conf
包含单行的文件nameserver 192.168.1.1
。
注意:如果文件有文件被覆盖的警告,请先将其删除,然后重新创建。
答案2
编辑/etc/network/interfaces
如下:
auto lo
iface lo inet loopback
auto eth0
allow-hotplug eth0
iface eth0 inet static
address 192.168.1.50
netmask 255.255.255.0
gateway 192.168.1.1
broadcast 192.168.1.255
保存退出
然后键入以下命令:
sudo rm /var/lib/dhcp/*
重新启动您的系统
打开你的界面以太网0类型 :
sudo ip link set eth0 down
sudo ip link set eth0 up