Smart methods for an Embedded Linux device to detect Internet connectivity

connectivity, embedded, icmp, linux

Solution

As the guy who wrote that answer referenced by ChristopheD, that's not the approach I'd use here. It worked for the other question, because in that case we were checking for the presence of a direct PPP link from the current machine - in this case, you're connected to an abitrary network which may or may not already have a default route, independent of its wider internet connectivity.

Since you need global DNS connectivity for your app, I'd check for that - look up an address you know will always exist - like an `NS` type query for the `com.` domain. Use a reasonably long timeout and/or retry a few times before giving up. Something like this:

dig NS +aaonly com.

Ignore the output and test the exit value - 0 indicates the lookup was able to contact the root servers, anything else and it wasn't.

Problem

Our team is developing a Internet Media device based on Linux 2.6. Currently we detect whether Internet connectivity is established (via a wired Ethernet i/f) by pinging www.google.com Some networks we have tested the device on do not support ICMP packet forwarding so our application code mistakenly reports the Internet as unavailable in this case. Does anyone know of a more refined approach to deducing whether Internet connectivity is available through /dev/eth0 without resorting to pinging a well-known service?

Original source