You are not logged in.

#1 2017-07-13 11:50:54

tom.ty89
Member
Registered: 2012-11-15
Posts: 897

"definitive" way to determine "internet connectivity"?

On other platform, the operating system will probe whether a certain network connection provides "intermet connectivity", like on Android (for WiFi) and on Windows.

Usually on Linux when we want to know if we get internet connectivity, we would try to ping a public server like 8.8.8.8 (assuming we got ping response from a host in the LAN). However, this method is not exactly "scientific", for the fact that if all public servers a person knows can be down (while there are servers he/she doesn't know are up). Of course in reality this will probably never happen but logically speaking it is not impossible.

So I wonder if there is a "definitive" way to determine if we have internet connectivity, but the question is, what's the definition "internet connectivity"?

The definition I can think of is, the default gateway/route is doing NAT for our private address to a public address (while maybe whether it can actually reach the internet is not the concern).

So my question is, is the definition I suggested correct? If so, is there a way we can determine it is the situation of a (W)LAN connection?

P.S. Sorry if it's off-topic...

Offline

#2 2017-07-13 12:12:38

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,523
Website

Re: "definitive" way to determine "internet connectivity"?

tom.ty89 wrote:

So my question is, is the definition I suggested correct?

Well that depends ... on what your definition of correct is.  Let's avoid that infinite regress: "correct" is meaningless in this context.  If you decide on a definition of internet connectivity, then we can find a way to test for it.  But without some concrete definition, there can be no real test.

The very phrase "internet connectivity" is a useful abstraction, but as a high level abstraction it's not at all meaningful for what you are asking about.  The "internet" is not a singular thing you can either be or not be connected to.  It is an abstract concept of a vast number of other computers.  If, as described in your scenario, you can ping 8.8.8.8 but not other systems, or vice versa, how would you ever say one is connected to the "internet" and the other not?  To do so you'd have to partition the vast number of other computers in the world into thost that are "the internet" and those that aren't.  This is clearly absurd.

Perhaps the only meaningful operational definition of "the internet" would be based on the proportion of public servers.  If, somehow, there is a schism and 20% of public servers are completely unreachable from the other 80% and vice versa - so we have 80% of the computers interconnected an 20% interconnected, but no connections between those two pools - then perhaps you'd call that 80% "the internet".  But what if it's 70/30, or 60/40 ...

In practice any definition of internet connectivity that depends on estimating the portion of public servers you can connect to is useless.  You aren't going to ping billions of servers to calculate a metric of what proportion you can reach.  But short of this, why is pinging 8.8.8.8 or any other arbitrary public server not a valid test?

Very rarely does any test have 100% specificity and 100% sensitivity.  Pinging a single public server has 100% specificity: if it works, you're connections are good.  With a reliable public server, you can get very high sensitivity: if pinging 8.8.8.8 fails, it's more likely a problem at your end than at google's.  But throw in one or two other fallback public servers with no relation to google, an you can acheive very very high sensitivity too.

Now if you just want to know if you are connected to your local router - well, just ping the local router!

You could also explore /proc/net and get any number of transmission metrics.  Many of them useful, but I don't think any of them would have an ROC nearly as useful as just pinging one or two public servers.

Now you also mention how other OS's can have a nice simple metric.  I have no idea what they measure: but there is no magic - they may have a simple metric, but that doesn't mean it is accurate.  If you want simple: flip a coin.  Heads you're connected, tails you're not.  If you want something that actually represents reality then don't expect it to be *that* simple.

You wish to have some abstract model of your "connection to the internet" and you seem to want the one that is somehow objectively correct.  Remember, though, that all models are wrong; some are useful.  Pinging a couple reliable public servers is IMHO the most useful.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2017-07-13 12:37:51

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: "definitive" way to determine "internet connectivity"?

So, as a summary:

There is no perfect way.

A quick and dirty way is e.g.:

timeout -s KILL 2.5 "ping -c 1 -w 2 www.some-reliable-server-of-yours.com" &> /dev/null

Offline

#4 2017-07-13 14:58:20

tom.ty89
Member
Registered: 2012-11-15
Posts: 897

Re: "definitive" way to determine "internet connectivity"?

Trilby wrote:

Now if you just want to know if you are connected to your local router - well, just ping the local router!

So let's say we leave "the internet" out of our scope/discussion.

Is is possible to know whether the router does NAT for a client, just from the client itself but not relying on any server beyond the NAT (i.e in the "WAN" it is connected)? If so, perhaps even knowing the IP address the client is NAT'd to? (i.e. knowing my external IP without any "my IP address" sites)

P.S. And of course I am leaving the admin interface of the router out of consideration here.

Offline

#5 2017-07-13 15:28:44

Docbroke
Member
From: India
Registered: 2015-06-13
Posts: 1,433

Re: "definitive" way to determine "internet connectivity"?

I guess we can ping our ISP. IP of ISP can be found using traceroute.

Offline

#6 2017-07-13 23:58:36

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: "definitive" way to determine "internet connectivity"?

In practice, other OSes do this by testing against a server run by the OS developers and checking for valid responses, thereby proving both that the internet is available (because it is talking back to us!) and that you aren't trapped behind a captive portal.

In fact, that is why those other OSes can provide a popup saying "Well, you have internet but you might still need to login to something".

And in fact, that is why NetworkManager has /usr/lib/NetworkManager/conf.d/20-connectivity.conf

[connectivity]
uri=http://www.archlinux.org/check_network_status.txt

Which does exactly what it sounds like it should do.

(To be more specific, it will check if the connectivity uri responds with the message body in response= which defaults to "NetworkManager is online".)

Last edited by eschwartz (2017-07-14 00:05:59)


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#7 2017-07-14 06:05:07

HiImTye
Member
From: Halifax, NS, Canada
Registered: 2012-05-09
Posts: 1,072

Re: "definitive" way to determine "internet connectivity"?

there are different levels of connectivity.
can you resolve internet addresses?
can you send and receive useful ICMP requests?
can you establish a TCP connection and successfully send and receive data?

each of these has a different answer

Offline

#8 2017-07-14 12:04:52

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,523
Website

Re: "definitive" way to determine "internet connectivity"?

And none of the above questions are really what someone would care about.  Any one of these levels is almost always just a proxy for a much more specific question.  Generally one doesn't really care if they can ping 8.8.8.8, but that is a useful test in that if they can ping 8.8.8.8 they can probably also do whatever other thing they want that requires network connectivity.  But evening pining a public server is not the definitive test for that other thing - it's just a useful proxy.

If you want to know if you'll be able to get an imap connection to gmail.com and retrieve your email, then the only perfect test is an attempted to get an imap connection to gmail.com and retrieve your email.  Either it will work, or it will not.  It is a perfect (but not so useful) model of the outcome.

If you want to know if you'll be able to see recent forum activity on bbs.archlinux.org in your web browser, then the only perfect test is to attempt to see recent forum activity on bbs.archlinux.org in your web browser.  Again, a perfect, but not so useful model of the outcome.

Everything else is an imperfect (non-definitive) test of these outcomes.  But most imperfect tests will be far more useful.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#9 2017-07-14 16:29:04

seth
Member
Registered: 2012-09-03
Posts: 51,017

Re: "definitive" way to determine "internet connectivity"?

wrt comment #4, I'd say OP wants to get his WAN IPv4 w/o asking the router or some external service (conky related question?)
Otherwise and w/o further specification of the original question, this is a TGN. "The internet" does not exist as an entitiy by explicit design, so you cannot query its state by definition.

That said ...
https://www.youtube.com/watch?v=iDbyYGrswtg
https://www.youtube.com/watch?v=Vywf48Dhyns

(it's "The IT Crowd" - if you don't know what that is: watch it)

That said: if I want to know whether I've got a working WAN (no further investigation on where the buck stops), I just ping google.com. When google is down, the rest of "the internet" likely is as well... :-P

Offline

#10 2017-07-15 23:26:31

rowdog
Member
From: East Texas
Registered: 2009-08-19
Posts: 118

Re: "definitive" way to determine "internet connectivity"?

For a "definative" answer you can test with

traceroute -n 8.8.8.8

As Trilby said, if just want to know if a service works, try it, if not, troubleshoot it, starting with the above.

Offline

#11 2017-07-19 15:00:56

rsmarples
Member
Registered: 2009-05-12
Posts: 287

Re: "definitive" way to determine "internet connectivity"?

The most foolproof way is just by looking at host: is there a default route where the outbound interface has an active carrier and address?
If yes then we can assume connectivity, if not then there is no connectivity.

Anything else we just have to hope and pray - at best you can determine host reachability, nothing more.
For example, you could install a node claiming the address of 8.8.8.8 on the local network which isn't owned by Google nor provides their DNS services - it could infact provide malicious DNS or there just to annoy applications who think 8.8.8.8 means internet access when really the router is broken.

Lastly all above tests assume IPv4 - you can have internet connectivity over IPv6 by itself.

Offline

Board footer

Powered by FluxBB