i came accross a problem i was yet unable to solve with my raspberry pi.
what i want is the following:
- startup wifi on boot with no ethernet connected
- when plugging in ethernet cable switch to ethernet and stop wifi
- when removing ethernet cable restart wifi
before posting my config files i will explain what is happening right now:
- wifi starts up on boot, i can login via ssh and everything works fine
- when i plugin ethernet, the wifi goes down and the pi is then accessible through the ethernet ip.
But here is where the problems start:
i cannot access the internet through this, as there is no default gateway set!
sure i can just type route add default gw xxx.xxx.xxx.xxx but i want this to work
automatically.
- when i remove the ethernet cable the wifi seems to startup again (light flickering on the dongle) but it is not accessible anymore
neither via ssh nor through port 80 or antyhing else
i already invested many hours on google to find information on the subject, and honestly there is alot of information out there. sadly many answers are very different, yet they seem to work for someone or the other. my files currently look like a mix of the many different things i found on the web. i hope you can help me to get this working, or explain to me that what i want is not possible and why.
/etc/default/ifplug
INTERFACES=""
HOTPLUG_INTERFACES="eth0"
ARGS="-q -f -u0 -d10 -w -I"
SUSPEND_ACTION="stop"
/etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="MYSSID"
psk="MYPSK"
id_str="wifi"
}
/etc/network/interfaces
auto lo
iface lo inet loopback
iface eth0 inet static
address 192.168.0.99
netmask 255.255.255.0
gateway 192.168.0.254
post-up route add default gw 192.168.0.254
pre-down route del default gw 192.168.0.254
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
wireless-power off
iface wifi inet static
address 192.168.0.89
netmask 255.255.255.0
#gateway 192.168.0.254
post-up route add default gw 192.168.0.254
pre-down route del default gw 192.168.0.254
iface default inet dhcp
post-up route add default gw 192.168.0.254
pre-down route del default gw 192.168.0.254
as you can see i disabled the power management on the wifi and tried to add the gateway after either interface comes up.
as far as i can tell these pre and post lines don't have any effect at all, since, as described earlier, there is no gateway set after i plug in the ethernet cable.
i also tried setting the gateway on both eth0 AND wlan0 which resulted in the wlan not being accessible at all. so i have it commented out on one of them.
i hope you guys can help me with an answer, as it's driving me nuts.
thank you very much for your time and effort.
iface default inet dhcp
or not - make up your mind? /etc/network/interfaces seems unnecessarily complex. If possible reserve addresses in your router rather than fiddle with static – Milliways Sep 23 '14 at 07:25id_str="name"
to define the interface name, but if not set it is "default". This means that this then calls dhcp on the interface. PS I agree the documentation is obscure, aand I am not sure I understand all the implicationss – Milliways Sep 23 '14 at 11:16