47

I'm struggling with my configuration of my Raspberry Pi. I want to achieve the following:

eth0: will be used with a static ip and can only connect to the local area network (this will be my NFS server) wlan0: Should connect to my wireless network for internet access

For some reason I'm unable to activate both connection at the same time (yes I have a good power supply). The ethernet will disable the wireless for no reason at all. If i finally get the both up then I'm unable to ping google.com. My question how should I do this correctly? I have the following in my interfaces file:

auto lo
iface lo inet loopback

auto eth0
allow-hotplug eth0
iface eth0 inet static
address 192.168.1.101
netmask 255.255.255.0
gateway 0.0.0.0

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

iface home inet static
address 192.168.0.157
netmask 255.255.255.0
broadcast 192.168.0.255
gateway 192.168.0.1

iface default inet dhcp

Kind Regards, and thank you very much!

DanFritz
  • 996
  • 1
  • 9
  • 13
  • make sure you are running the latest firmware and software. i struggled allot on the old firmware it drove me nuts. upgraded everything from scratch and it has supplicant integrated and its very easy to conenct – Piotr Kula Aug 06 '13 at 16:18
  • 1
    I think the solution should be posted as an answer... – jmc Dec 28 '13 at 17:31
  • thank you for you in depth details on this subject, i have managed to implement what was written here and got my pi to work with both adapters. –  Dec 28 '13 at 16:48
  • 1
    It is poor form and damages the usability of the site, to "update question to include answer". You should post answer to your own question. Then it will be easy to find for others -- and may attract upvotes from the people it helps – Frames Catherine White Jul 24 '14 at 01:13

2 Answers2

26

This applies to Raspbian Wheezy prior to 2015-05-05 for later (and Jessie/Stretch) See How do I set up networking/WiFi/Static IP

As suggested by the community, my answer extracted from the question.

I got it working right now so I'll share all my configuration files with the community. Firstly lets look at the wpa_supplicant.conf file:

pi@raspberrypi ~ $ sudo cat /etc/wpa_supplicant/wpa_supplicant.conf 
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="****"
    scan_ssid=1
    proto=RSN
    key_mgmt=WPA-PSK
    pairwise=CCMP TKIP
    group=CCMP TKIP
    psk="****"
    id_str="home"
    priority=5
}

Next my new update interfaces file

pi@raspberrypi ~ $ sudo cat /etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
allow-hotplug eth0
iface eth0 inet static
address 192.168.1.101
netmask 255.255.255.0

auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
address 192.168.0.157
netmask 255.255.255.0
broadcast 192.168.0.255
gateway 192.168.0.1

iface default inet dhcp

And now comes the tricky part, you have to disable the hotplugging of the eth0 device (else it will disable your wlan0). You do this by edting the following file:

pi@raspberrypi ~ $ sudo cat /etc/default/ifplugd 
INTERFACES="eth0"
HOTPLUG_INTERFACES="eth0"
ARGS="-q -f -u0 -d10 -w -I"
SUSPEND_ACTION="stop"

I also have the following in my startup script, this will make sure my wifi does get started up (sometimes for no reason at all it would not start). You also have to kill the ifplugd daemon on the eth0 device:

pi@raspberrypi ~ $ sudo cat /etc/rc.local
#!/bin/sh -e

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi

# Disable the ifplugd eth0
sudo ifplugd eth0 --kill
sudo ifup wlan0

exit 0

And that should work!

Milliways
  • 54,718
  • 26
  • 92
  • 182
DanFritz
  • 996
  • 1
  • 9
  • 13
  • 3
    You don't need to disable the whole `ifplugd`. Instead, just disable (delete) the offending symlink `/etc/ifplugd/action.d/action_wpa`, which keeps wlan0 from working when Ethernet is connected. – minmaxavg Apr 12 '16 at 07:35
  • to disable the hotplugging of the eth0 device, shouldn't we delete the `auto etho` lines? Furthermore I still have `:~ $ sudo service isc-dhcp-server start Job for isc-dhcp-server.` – Revolucion for Monica Jun 06 '16 at 08:37
  • A small tip for future users: This answer works very well. If you want to know the gateway IP address, just enter `ip r | grep default` –  Dec 27 '19 at 17:01
8

If a device does not have internet access or other access outside the local subnet, then you should eliminate the gateway. Listing a gateway on both interfaces is likely the culprit.

If the ethernet is for the local subnet only remove that gateway.

Tevo D
  • 841
  • 8
  • 13
  • Tevo D is correct. When your eth0 is connected you will have a default route (network 0.0.0.0) out your eth0 interface which will cause off-network traffic to get routed out your eth0 interface and into the ["bit-bucket"](http://en.wikipedia.org/wiki/Bit_bucket). – HeatfanJohn Aug 06 '13 at 16:20
  • Oke I removed the gateway on eth0. Now I see that my wireless is connected (running iwconfig) but when I run ifconfig the wireless is does not use the static IP address or gateway I assigned (it stays blank). Any clue on that one? – DanFritz Aug 07 '13 at 08:47
  • Found the solution, thanks for your help. I've updated my question with all my configuration files (for other people) – DanFritz Aug 07 '13 at 09:37
  • @TevoD I used your advice to comment gateway, It works but for 1 min,then WiFi disconnected.(but Ethernet is worked), could you help me – H.Ghassami Nov 20 '17 at 09:16