terminal tool to check internet connection when disconnection
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
terminal tool to check internet connection when disconnection
Hii
I would like to know is there any terminal tool that i can use to run in terminal constantly be it internet is ok or internet got disconnected ?
Recently i have got internet disconnection issue with my service provider. I often found out my router reset itself and it is trying to connect or something.. hence lost lan and internet. sometime got lan but no internet.
but, these tools can't help me to know when internet is again connected .. because i saw router signal Indicator is normal, but both ping and mtr keeps showing as not connected... until i cancel and rerun the command.. then it shows it is connected..
if i need to rerun when internet is back to normal, then, those tools are useless in this case.
Ping works.
You can ping a domain, then you know that both internet and name resolution work.
You can ping a numerical IP address, then you know that internet works.
It is entirely possible for your router to be connected to the internet, but not your computer.
It can have dozens of reasons.
Ping works.
You can ping a domain, then you know that both internet and name resolution work.
You can ping a numerical IP address, then you know that internet works.
It is entirely possible for your router to be connected to the internet, but not your computer.
It can have dozens of reasons.
I am sure ping does not work in this scenario.
I have tried many time in many days when my internet got disconnected;
When my internet got disconnected, i can see router blinking
Then i run "ping www.google.com"
it just shows "failure in name resolution." **this is when router is still initializing itself**
it shows "64 bytes from _gateway (192.168.0.1) ... **this is when the router lan has established, but internet connection is not establish yet***
and it just keeps showing "64 bytes from _gateway (192.168.0.1) ..." this for ever.. **even after internet connection has established for hours. **
until i pressed "ctrl-c" and retype "ping www.google.com", then only it will shows " 64 bytes from fra16s12-in-x04.1e100.net...."
Please look at the attached photo of the ping.. the "upper portion" of ping was done when the router resetting. I forgot about the ping.. and you can see, the icmp_seq was 8934.... , it still shows "ping gateway" only even i had have internet for long time already.
the "lower portion " is the when i redo ping after internet has already established.
See the different..
mtr still showing "gateway" ... only even this very second.. because i have not ctrl-c it and redo mtr.
hence these 2 software can't inform me when internet has established.
sometime i am busy typing,.. i won't realize if internet connection has established or not (when i am busy typing)... hence i want a simple package will tell me if internet has being established instead of just lan has being establish..
When your router disconnects from the internet (for any reason) you will not get name resolution nor any other communication such as ping responses.
A constantly running process may get locked into one response and not be able to see changes, although ping, if working before the link dies, should recover since it already knows the IP it is sending to. If used when the link is already broken you cannot rely on the response as you can tell. Pinging with a known IP address on the internet would avoid the invalid response from your router. It either works or the packet is lost.
The real issue seems to be your provider is unreliable and that cannnot be fixed at your end. One other thing that may be in play is power to your router, or a bad cable connection. The provider should fix the cable but you are responsible for the power. You should be calling them and complaining every time the link goes down instead of trying to work around it. With enough trouble calls they should actually fix it, and if not then you should get a different provider.
Err.. is there difference between ping nummeric ip vs ping dns name such (www.google.com ) ?
Yes, a big difference.
Pinging a numeric IP goes directly to the address.
Pinging a URL requires that dns has to be called to resolve the name and obtain the IP before the ping can be sent.
Once the address is available then the ping part is the same.
You can also ping your router's ip address to check whether the connection to the router is active. If you can ping your router, but not the Big Wide World, the issue is definitely with your internet connection, and not within your local network.
Another useful command in traceroute. It can tell where the connection is going bad. See man traceroute for details.
Building on what computersavvy said above, I've had experiences in which I could ping 8.8.8.8 (which is a Google IP), but could not ping google.com. That tells me that I was experiencing DNS resolution issues (the issues were out of my control, but were quickly resolved).
A constantly running process may get locked into one response and not be able to see changes,
For a situation like this, I have a tiny bash script that uses the -c (count) option for ping.
I don't have the code handy right now, but basically its an infinite loop that calls 'ping -c3 <somewhere>'.
This means ping only tries 3 times then quits, so each invocation is brand new and gets around the 'stuck/hung syndrome.
HTH
PS as noted above, you can annoy people if you overuse it, so my loop checks the rtn code and if it sees '0'
It uses pings to check for a network connection and logs when it drops and when it returns. I used our webserver hosted elsewhere to ping from the office I was at and the fallback was google.com. Once the ping to the webserver stopped, then it tried to ping google and when that failed it would register the network as down. I think it pinged both until the network returned, then it would fall back to just the primary ping of the webserver.
Last edited by uteck; 12-03-2020 at 09:45 AM.
Reason: typo
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.