Networking

Raspberry Pi Jessie Wi-Fi 不適用於同一網路上的多個 IP

  • March 1, 2020

我想為具有相同 Wi-Fi 加密狗的同一網路使用兩個不同的靜態 IP 地址。我在不同的論壇上讀到,最好使用/etc/network/interfaces而不是dhcpcd.conf為此目的。所以我改變了/etc/network/interfaces這種方式:

auto lo
iface lo inet loopback

iface eth0 inet dhcp
auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
   address 192.168.0.60
   netmask 255.255.255.0
   gateway 192.168.0.10
   wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
auto wlan0:0
allow-hotplug wlan0:0
iface wlan0:0 inet static
   address 192.168.0.61
   netmask 255.255.255.0
   wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

現在的問題是,在大多數情況下,我無法 ping 網路的任何成員。在前 10 秒內,一切正常,然後我幾乎沒有任何連接。

ifconfig顯示以下內容:

lo        Link encap:Lokale Schleife  
         inet Adresse:127.0.0.1  Maske:255.0.0.0
         inet6-Adresse: ::1/128 Gültigkeitsbereich:Maschine
         UP LOOPBACK RUNNING  MTU:65536  Metrik:1
         RX packets:1237 errors:0 dropped:0 overruns:0 frame:0
         TX packets:1237 errors:0 dropped:0 overruns:0 carrier:0
         Kollisionen:0 Sendewarteschlangenlänge:1 
         RX bytes:100748 (98.3 KiB)  TX bytes:100748 (98.3 KiB)

wlan0     Link encap:Ethernet  Hardware Adresse b8:27:eb:a2:4b:72  
         inet Adresse:192.168.0.60  Bcast:192.168.0.255  Maske:255.255.255.0
         inet6-Adresse: fe80::ba27:ebff:fea2:4b72/64 Gültigkeitsbereich:Verbindung
         UP BROADCAST MULTICAST  MTU:1500  Metrik:1
         RX packets:15498 errors:0 dropped:10634 overruns:0 frame:0
         TX packets:5446 errors:0 dropped:0 overruns:0 carrier:0
         Kollisionen:0 Sendewarteschlangenlänge:1000 
         RX bytes:5910381 (5.6 MiB)  TX bytes:722284 (705.3 KiB)

wlan0:0   Link encap:Ethernet  Hardware Adresse b8:27:eb:a2:4b:72  
         inet Adresse:192.168.0.61  Bcast:192.168.0.255  Maske:255.255.255.0
         UP BROADCAST MULTICAST  MTU:1500  Metrik:1

並且 route -ne 具有以下輸出:

Ziel            Router          Genmask         Flags   MSS Fenster irtt Iface
0.0.0.0         192.168.0.10    0.0.0.0         UG        0 0          0 wlan0
192.168.0.0     0.0.0.0         255.255.255.0   U         0 0          0 wlan0

我也停止了 dhcpcd,IP 不在路由器的 dhcp IP 池中,並且使用一個靜態 IP 一切正常 有人知道我做錯了什麼嗎?

您可以將多個 IP 地址添加到您的wlan0介面,編輯/etc/network/interfaces如下:

auto lo
iface lo inet loopback

iface eth0 inet dhcp

auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
   address 192.168.0.60/24
   netmask 255.255.255.0
   gateway 192.168.0.10
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug wlan0
iface wlan0 inet static
   address 192.168.0.61/24
   wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

保存文件然後重新啟動。

鍵入以下命令:

sudo ip a

樣本輸出:

inet 192.168.0.60/24 brd 192.168.0.255 scope global wlan0
inet 192.168.0.61/24 brd 192.168.0.255 scope global secondary wlan0

要對其進行測試,您可以ssh192.168.0.60192.168.0.61

您可以使用該ip命令為您的網路介面設置一個臨時 IP:

sudo ip addr add 192.168.0.60/24 dev wlan0
sudo ip addr add 192.168.0.61/24 dev wlan0

引用自:https://unix.stackexchange.com/questions/403970