3

My pi is connected to my home router using wlan0, and have access to internet successfully

When I plug my pi with an Ethernet cable, connected to other router, not connected to internet, I cant ping anymore with answer "Destination Net Unreachable"

pi@bar:~ $ sudo ping -c 1 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
From 192.168.100.1 icmp_seq=1 Destination Net Unreachable

--- 8.8.8.8 ping statistics ---
1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms

If I ping using wlan0 it succeed:

pi@bar:~ $ sudo ping -c 1 -I wlan0 8.8.8.8
PING 8.8.8.8 (8.8.8.8) from 192.168.1.151 wlan0: 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=40 time=83.7 ms

--- 8.8.8.8 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 83.748/83.748/83.748/0.000 ms

My routing table:

pi@bar:~ $ netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.100.1   0.0.0.0         UG        0 0          0 eth0
0.0.0.0         192.168.1.1     0.0.0.0         UG        0 0          0 wlan0
192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 wlan0
192.168.100.0   0.0.0.0         255.255.255.0   U         0 0          0 eth0

So obviously eth0 is prioritize over wlan0, and with no internet access it cannot find 8.8.8.8.

How can I solve this problem? I want that any app (ping, curl whatever) will be able to reach internet, even if one of the interfaces (wlan0, eth0 or any other) is connected to a router with dead end?

cheers, Bar

2
  • If you run route -n you will see a metric. This is the priority. You can specify parameters like priority=1 in etc/wpa_supplicant/wpa_supplicant.conf to specify priority between WiFi networks. You can also influence metrics, but I do not recall how.
    – Milliways
    Commented Apr 26, 2017 at 0:43
  • Thanks, I didn't made myself clear enough. I want to be able to ping even if wlan0's record at routing table is first, but the wifi network has no internet access but eth0 is perfect (the opposite of the case of the first post) . Is there any configuration that by bad reply from the first routing record try the next record? or my solution is to handle routing table records according to internet accessibility?
    – BarLesh
    Commented Apr 26, 2017 at 11:44

2 Answers 2

1

You have two default routes:

Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.100.1   0.0.0.0         UG        0 0          0 eth0
0.0.0.0         192.168.1.1     0.0.0.0         UG        0 0          0 wlan0

The default route is used for all ip packages that destination address does not belong to direct connected local networks. So all destination ip addresses to the internet will use the default route. The kernel can only use one default route. What route it uses is determined by the metric. It uses the default route with the lowest metric. You may have a look at details for this issue at In Linux, what metric has a route with no metric?.

The easiest way is to just delete the default route that shouldn't be used so you only have one. If you want the default route on eth0 then just execute:

rpi ~$ sudo ip route del default dev wlan0
0

Try removing the default route and adding one manually:

ip route del default
ip route add default via 192.168.1.1 dev wlan0

If this works, you'll have to find a way to execute this automatically every time your RPi connects to the network. My first guess would be to add this script to /usr/lib/dhcpcd/dhcpcd-hooks/.

2
  • Thanks, I didn't made myself clear enough. I want to be able to ping even if wlan0's record at routing table is first, but the wifi network has no internet access but eth0 is perfect (the opposite of the case of the first post) . Is there any configuration that by bad reply from the first routing record try the next record? or my solution is to handle routing table records according to internet accessibility?
    – BarLesh
    Commented Apr 26, 2017 at 11:44
  • @BarLesh In that case you'll need to look at the policy routing. Or you could make a script which pings a website once in a while, and alters the default route when there's no reply. Commented Apr 26, 2017 at 11:50

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.