如何在 raspberry pi 3 上设置多个 IP 地址

How to set multiple IP Address on a raspberry pi 3

我带了一个 USB 转以太网适配器,现在我将它的一端连接到 raspberry pi 3 上的 USB,另一端连接到以太网(这样我就可以为我的 pi 设置两个 IP 地址) .

注意:我也在 Raspberry Pi 3

上使用我的以太网端口

如果我断开我的以太网端口并仅通过 USB 连接到以太网适配器,我将无法通信。我假设我的 USB 以太网适配器没有发生任何通信。我希望这两个 IP 地址同时工作

然后我更改了 /etc/network/interfaces 文件,如下所示:

auto eth0
allow-hotplug eth0
iface eth0 inet static
address 192.168.147.146
netmask 255.255.255.0
gateway 192.168.147.255

auto eth0:0
allow-hotplug eth0:0
iface eth0:0 inet static
address 192.168.147.145
netmask 255.255.255.0

allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

这是我在终端的 ifconfig 输出:

eth0      Link encap:Ethernet  HWaddr b8:27:eb:0d:2b:28  
      inet addr:192.168.147.146  Bcast:192.168.147.255  Mask:255.255.255.0
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:71565 errors:0 dropped:928 overruns:0 frame:0
      TX packets:17901546 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000 
      RX bytes:6283723 (5.9 MiB)  TX bytes:1220265483 (1.1 GiB)

eth0:0    Link encap:Ethernet  HWaddr b8:27:eb:0d:2b:28  
      inet addr:192.168.147.145  Bcast:192.168.147.255  Mask:255.255.255.0
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

lo        Link encap:Local Loopback  
      inet addr:127.0.0.1  Mask:255.0.0.0
      UP LOOPBACK RUNNING  MTU:65536  Metric:1
      RX packets:910 errors:0 dropped:0 overruns:0 frame:0
      TX packets:910 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1 
      RX bytes:79976 (78.1 KiB)  TX bytes:79976 (78.1 KiB)

请告诉我您的建议.....

您的 USB 转以太网适配器是物理网络适配器,但您已将其设置为虚拟网络适配器。

尝试在您的 /etc/network/interfaces 文件中将 eth0:0 更改为 eth1

您的代码应如下所示:

auto eth0
allow-hotplug eth0
iface eth0 inet static
address 192.168.147.146
netmask 255.255.255.0
gateway 192.168.147.255

auto eth1
allow-hotplug eth1
iface eth1 inet static
address 192.168.147.145
netmask 255.255.255.0

allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf