Search code examples
linuxraspberry-piraspbianraspberry-pi3ethernet

How to set multiple IP Address on a raspberry pi 3


I brought a USB to Ethernet adapter, now I connected that to USB on raspberry pi 3 on one end and to the ethernet on the other end (So that I can set two IP address for my pi).

Note: I am also using my Ethernet port on Raspberry Pi 3

If I disconnect my Ethernet port and connect only through USB to Ethernet Adapter, I couldn't communicate. I assume that there is no communication happening with my USB-Ethernet Adapter. I want both the IP addresses work at a time

Then I've changed the /etc/network/interfaces file as shown below:

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

This is my output from ifconfig from the terminal:

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)

Please let me know your suggestions.....


Solution

  • Your USB to Ethernet adaptor is a physical network adaptor however you have set it up as if it were a virtual network adaptor.

    Try changing eth0:0 to eth1 in your /etc/network/interfaces file

    Your code should look something like this:

    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