MichaIng / DietPi

Lightweight justice for your single-board computer!
https://dietpi.com/
GNU General Public License v2.0
4.83k stars 495 forks source link

Configure Wifi as fallback LAN for Ethernet link not connected at boot #265

Closed WolfganP closed 6 years ago

WolfganP commented 8 years ago

As per https://github.com/Fourdee/DietPi/issues/264

As a basic connectivity model for DietPi, change the concept of current exclusive LAN connection (Eth OR Wifi) to a priority based one (activate wifi with preconfigured credentials if wired ethernet not present at boot)

It may later be expanded to simultaneous connectivity / both links active model if worthy.

spiderkeys commented 8 years ago

Would also like to support the notion of providing simultaneous connectivity/bridging the two connections, regardless of whether or not the wifi is infrastructure, adhoc, or AP mode.

Fourdee commented 8 years ago

@WolfganP Thanks for creating the request. As v115 is nearly completed, I'll add this to v116 and start work on it after v115 is released.

@spiderkeys Noted :+1: . We should be able to make that possible.

k-plan commented 8 years ago

Hi,

nice feature and can be really helpful. Which USB Wifi adapter (chip set) will be supported in DietPi out-of-the box adhoc or AP mode?

Tested five different units (chips: 1x TI, 2x ralink, 1x realtek, 1x atheros), not only one will work.

rhkean commented 8 years ago

probably best to let the kernel detect, then test for presence of wlan0.

WolfganP commented 8 years ago

From what I read at http://raspberrypi.stackexchange.com/questions/8851/setting-up-wifi-and-ethernet it seems that declaring both interfaces and keeping the proper credentials at wpa_supplicant.conf will work (plus disabling the hotplugging capability). And obviously not making the selection of interfaces exclusive at dietpi-config...

Fourdee commented 8 years ago

@rhkean @WolfganP

probably best to let the kernel detect, then test for presence of wlan0.

Yep, thats the plan. Currently DietPi is coded to only support 1 active adapter at any time, or both when using WiFi hotspot. Basically we just need to allow the user to enable and configure both adapters at the same time, and support it throughout DietPi scripts (eg: dietpi-config). Then we will probably let the kernel decide which one is actually used, for now.

I'am aiming to start work on this later tonight and tomorrow. My son is staying at his nans for the night, so I will get some time to really dig into this :).

WolfganP commented 8 years ago

Great!

Fourdee commented 8 years ago

@rhkean @WolfganP Done, available for v116. Wasn't as bad as I thought. Did most of the code work when I implemented the WiFi hotspot support in dietpi-config

We will let the kernel decide which connection is being utilized, when both are active.

Heres the commit: https://github.com/Fourdee/DietPi/commit/3f532cb2a124bb3740f0c14223173cbb406fa815

Fourdee commented 8 years ago

Removal of ifmetric to fix: https://github.com/Fourdee/DietPi/issues/515#issuecomment-247798038, breaks this ticket.

New method required.

Fourdee commented 7 years ago

Bonding: http://dietpi.com/phpbb/viewtopic.php?f=9&t=340&start=20#p4417 Does the following:

sibero80 commented 5 years ago

Hello Everyone, greetings from Colombia!

Currently my Diet-pi is setup with the Hotspot package, using a Wifi dongle (wlan0) and Ethernet (eth0) as internet source.

I'm interested on adding a second WiFi adapter (wlan1) as I wish to be able to switch to wlan1 if internet eth0 gets disconnected. (or maybe bonding both eth0 and wlan1 )

This is my current setup:

#/etc/network/interfaces
#Please use DietPi-Config to modify network settings.

# Local
auto lo
iface lo inet loopback

# Ethernet
allow-hotplug eth0
iface eth0 inet static
address 192.168.0.18
netmask 255.255.255.0
gateway 192.168.0.1
dns-nameservers 8.8.8.8

# Wifi Hotspot
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.42.1
netmask 255.255.255.0
#gateway 192.168.0.1
#dns-nameservers 8.8.8.8 8.8.4.4

# IP tables
up iptables-restore < /etc/iptables.ipv4.nat

From your previous post:

  1. Do yo thing the following setup would do the trick? (My second Wifi dongle has not arrived, so cannot test right now)
  2. How can I set up DHCP in wlan1 in a way that does not require the IP Adress, Netmask and Gateway to be specified?
#/etc/network/interfaces
#Please use DietPi-Config to modify network settings.

# Local
auto lo
iface lo inet loopback

# Ethernet
allow-hotplug eth0
iface eth0 inet static
address 192.168.0.18
netmask 255.255.255.0
gateway 192.168.0.1
dns-nameservers 8.8.8.8
    bond-master bond0
    bond-primary eth0
    bond-mode active-backup

# Wifi Hotspot
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.42.1
netmask 255.255.255.0
#gateway 192.168.0.1
#dns-nameservers 8.8.8.8 8.8.4.4

# IP tables
up iptables-restore < /etc/iptables.ipv4.nat

# Wifi Fallback
allow-hotplug wlan1
iface wlan0 inet dhcp
address 192.168.0.100
netmask 255.255.255.0
gateway 192.168.0.1
wireless-essid WIFI_SSID
wireless-key WIFI_KEY
wireless-mode Managed
wireless-power off
wpa-ssid WIFI_SSID
wpa-psk WIFI_KEY
#dns-nameservers 8.8.8.8 8.8.4.4
    bond-master bond0
    bond-primary eth0
    bond-mode active-backup

# Define bond
auto bond0
iface bond0 inet dhcp
    bond-slaves none
    bond-primary eth0
    bond-mode active-backup
    bond-miimon 100

Thank you!