0

I am trying to make my Pi accessible via SSH regardless of which wireless network it is connected to. For this end I have setup a static IP address to the wlan0 interface. Problem is that I cannot SSH to the Pi, ping it from other devices or ping anything in the network from the Pi. However, I can browse internet and ping addresses such as www.stackexchange.com from the Pi.

The problem goes away if I shutdown the eth0 interface with sudo ifconfig eth0 down. Then everything works perfectly. However, eth0 is back and running after a reboot. How can I direct all traffic to prefer the wlan0 interface instead of (not connected) ethernet?

I have the model 3b and am running Raspbian Jessie. My network/interfaces file

auto lo
iface lo inet loopback

auto eth0
allow-hotplug eth0
iface eth0 inet manual

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

At the end of my dhcpcd.conf I have

interface wlan0
static ip_address=192.168.0.240/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1

and 192.168.0.240 is the address I try to ping/connect to.

When I ping other devices from the Pi while eth0 is active, I can see the Pi tries to ping from the address of the ethernet, although there is no ethernet cable attached and I want wifi to be used. This is how I figured to disable it and it seems to be the cause of the problem. Moreover, upon booting I get the message.

Waiting for network for 110 additional seconds

In a nutshell: Pi seems to use wrong network interface, how to fix?

Edit: ifconfig output

eth0      Link encap:Ethernet  HWaddr b8:27:eb:df:e2:1a
          inet addr:192.168.43.24  Bcast:192.168.43.255  Mask:255.255.255.0
          inet6 addr: fe80::8ed2:5c2a:b54f:d28c/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:420 errors:0 dropped:0 overruns:0 frame:0
          TX packets:121 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:37528 (36.6 KiB)  TX bytes:19320 (18.8 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:88 errors:0 dropped:0 overruns:0 frame:0
          TX packets:88 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1
          RX bytes:7689 (7.5 KiB)  TX bytes:7689 (7.5 KiB)

wlan0     Link encap:Ethernet  HWaddr b8:27:eb:8a:b7:4f
          inet addr:192.168.43.224  Bcast:192.168.43.255  Mask:255.255.255.0
          inet6 addr: fe80::fc57:9494:65ae:1475/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2547 errors:0 dropped:946 overruns:0 frame:0
          TX packets:146 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:316994 (309.5 KiB)  TX bytes:17769 (17.3 KiB)
3
  • Your question is incomplete. What does "it tries to ping from the address of the ethernet, although the cable is not plugged". What is Ethernet connected to? What does ifconfig show?
    – Milliways
    Commented Sep 20, 2016 at 23:54
  • I edited the part in question. I have no ethernet connected whatsoever. When I ping an ip-address, I get the host unreachable message where it shows the ip-address if the ethernet interface as the ping sender. I'll post my ifconfig when I get home but I can see ip-addresses for ethernet and wlan and packet traffic seems to go through wlan.
    – milez
    Commented Sep 21, 2016 at 5:38
  • @Milliways I added my ifconfig output
    – milez
    Commented Sep 21, 2016 at 17:01

4 Answers 4

2

Disable your eth0 interface on boot if you really don't need it.

Add sudo ifconfig eth0 down to /etc/rc.local, before any exit 0.

Addendum: The waiting for network problem could be solved by removing a permanent ip=x.x.x.x entry in /boot/cmdline.txt.

But disabling the eth0 interface still helped in preferring the wireless interface.

8
  • This seems to do the trick, thanks! Not sure if it is the best solution but it works.
    – milez
    Commented Sep 21, 2016 at 17:08
  • I still get the "Waiting up to 110 more seconds for network" message tho..
    – milez
    Commented Sep 21, 2016 at 17:18
  • There is one more weird thing after doing this: I can still SSH and ping the ip address of the ethernet interface. How come? ifconfig only shows wlan0..
    – milez
    Commented Sep 21, 2016 at 17:21
  • The waiting thing might be solved by replacing all occurences of auto in your /etc/network/interfaces with allow-hotplug, or at least for the offending interface card. As for the responding, down interface: the IBM knowledge base says about ifconfig down: "Marks an interface as inactive (down), which keeps the system from trying to transmit messages through that interface. If possible, the ifconfig command also resets the interface to disable the reception of messages. Routes that use the interface, however, are not automatically disabled." Maybe it wasn't possible to disable it. Commented Sep 21, 2016 at 19:19
  • 1
    Wow, turns out the /boot/cmdline.txt was the problem. I had an ip-address there. Removed it and no other changes were needed, works great now O.o Maybe add that to your answer
    – milez
    Commented Sep 22, 2016 at 4:35
2

Your eth0 has 192.168.43.24 and wlan0 192.168.43.224. Neither of these agrees with 192.168.0.240/24 which you have attempted to set as static. (I will add my usual comment - there are better ways than using static.)

It is unclear what network you are trying to ping from, but presumably it is on a different subnet.

The fact that you have an inet address on eth0 implies the link is getting an address from somewhere, either it is connected or you have assigned it.

You have presumably misconfigured something, and supplied insufficient information for anyone to debug.

The kludge suggested, which you seem to have accepted, is just that - a kludge. Some of the other suggestions are just ways of avoiding the real problem, and will likely cause problems in future.

I suggest you actually solve your real problem, or just re-install the OS and start again.

3
  • This is good! Can you give me a keyword hint to what you consider better than using static? I've been using that for a while now, and am curious. Commented Sep 22, 2016 at 7:11
  • 1
    Raspbian has avahi (which is a zero-conf implementation) installed by default. The "Connecting a Computer to the Pi" section in How do I set up networking/WiFi/Static IP describes this.
    – Milliways
    Commented Sep 22, 2016 at 7:28
  • Interesting. Thanks for writing that. We're running several raspis in our lab, and I think using static will be preferable to using avahi for us, as we need to forward ports to specific raspis, using their IPs, through our router. Commented Sep 22, 2016 at 8:07
1

If your problem is solved by sudo ifconfig eth0 down, simply remove lines

auto eth0
allow-hotplug eth0
iface eth0 inet manual

from /etc/network/interfaces so it never goes up. This will also speed up your boot time since you won't be bringing the interface up and down unnecessarily.

3
  • Are you sure this is suitable for Jessie? I read the interfaces file should be left alone..
    – milez
    Commented Sep 21, 2016 at 17:19
  • Also waits for network at startup although wireless is available.. And eth0 is up after booting.
    – milez
    Commented Sep 21, 2016 at 17:28
  • That shouldn't happen, unless you have heavily customized your startup scripts. Do you have any scripts in network/interfaces.d? Commented Sep 21, 2016 at 20:03
0

Maybe things would be easier if you keep the stock configuration on the pi and configure the DHCP daemon in your router to assign a fixed IP to the MAC address of the PI's wifi.

Additionally: Having SAMBA running on your PI will make it announce its name, so that it can be seen by windows machines on your net.

1
  • I'm sorry but I cannot change anything in the router. And windows is not the only client platform, but I will look into SAMBA.
    – milez
    Commented Sep 20, 2016 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.