如何在 Eth0 中將 Raspbian 連接到 Internet?
我在 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 的第 2 次添加
我將地址從to更改為從
192.168.1.50
to192.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.3ms 所以在 <10ms
- ping 8.8.8.8 像 8ms 所以在 <30ms
- 用 8 毫秒 ping google.com 成功
如何通過 Eth0 將 Raspbian 連接到 Internet?
建議您將靜態配置轉換為 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
。注意:如果文件有關於文件被覆蓋的警告,請先將其刪除,然後再重新創建。