4

I have a raspberry 2 with a wifi interface and an ethernet interface. wifi is my main connection with the ability to just plug in the ethernet as a backup method. I want to assign different static address for each interface.

What I want is to be able :

  1. to boot with only the USB wifi connected on the first address
  2. to boot with only the ethernet connected on the second address
  3. to boot with both wifi and ethernet and be able to use both addresses
  4. to boot with only the wifi; then hotplug the ethernet and be able to use both addresses.
  5. when both wifi and Ethernet are connected, to be able to keep the other connection when one of them is down for a reason or anothe.

I couldn't manage to do this. If someone could help me I would be very thankful.

Here's my /etc/network/interfaces file :

auto lo
iface lo inet loopback

auto wlan0
#allow-hotplug wlan0
iface wlan0 inet static
address 192.168.1.10
netmask 255.255.255.0
gateway 192.168.1.1
wpa-ssid my-network
wpa-bssid XX:XX:XX:XX:XX:XX
wpa-psk  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

auto eth0
iface eth0 inet static
address 192.168.1.20
netmask 255.255.255.0
gateway 192.168.1.1

migrated from raspberrypi.stackexchange.com Jun 28 '15 at 12:09

This question came from our site for users and developers of hardware and software for Raspberry Pi.

  • 1
    There is a potential complication if you are using Raspbian or another distro which configures ifplugd by default, although it maybe a helpful complication WRT #4, hotplugging ethernet. – goldilocks Jun 28 '15 at 12:11
  • You say what you want to happen but not what problem you are experiencing. – user1794469 Jun 28 '15 at 15:26
7

I would use device bonding, meaning you are creating a new virtual device for which you assign the network settings (e.g. IP address, mask, etc.) and then you enslave both the ethernet and wifi interfaces to that interface.

Something like:

 $ sudo modprobe bonding
 $ sudo ifconfig bond0 192.168.0.1 netmask 255.255.0.0
 $ sudo ifenslave bond0 eth0 wlan0

This has the advantage of covering all your scenarios from 1 to 5 with one exception: you have only 1 IP address. If that would be a problem, then you could always create an "alias" (e.g. bond0:0) and give a different IP address for that one. Then you would always have both IP addresses reachable even if only 1 interface is active.

More details can be found online. E.g.: http://www.codekoala.com/posts/bonding-eth0-and-wlan0-arch-linux/

4

Bonding was exactly what I needed, so I adapted this answer. I can backup both interfaces and designate the ethernet interface as the primary one. In fact I didn't want a different address for each interface. I thought I had to do it with different ones but the solution with only one address and automatic backup is exactly what I wanted. (I also tested with 3 different addresses and it worked.)

Here's my new /etc/network/interfaces file:

auto lo
iface lo inet loopback

auto bond0
iface bond0 inet static
address 192.168.1.10
netmask 255.255.255.0
network 192.168.1.0
gateway 192.168.1.1
# Bonding
bond-slaves none
bond-primary eth0
bond-mode active-backup
bond-miimon 100
bond-downdelay 200
bond-updelay 200

auto wlan0 
#allow-hotplug wlan0
iface wlan0 inet manual
# Bonding
bond-master bond0
bond-primary eth0
bond-mode active-backup
wpa-ssid xxxxxxxxxxxxxxx
wpa-bssid XX:XX:XX:XX:XX:XX
wpa-psk  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

auto eth0
iface eth0 inet manual
# Bonding
bond-master bond0
bond-primary eth0
bond-mode active-backup
0

I have accomplished something similar to what you are describing using 2 wifi interfaces and wired Ethernet concurrently.

  • The wired Ethernet is connected to a test network.
  • The 1st wifi adapter is configured as a AP using hostapd for initial configuration.
  • The 2nd wifi adapter is connected to the local wifi network for access throughout the building.

Routing is off since this setup is only for access to the test network. The only "trick" was using wicd-curses to configure the system to connect to the local wifi network and keep the wifi interfaces up when the wired network was connected. This no doubt takes care of the ifplugd issues @goldilocks mentioned. The prefer_wired option on the wicd manpage is the key.

I've used this successfully with 2 different RPi2B.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy