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!
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I'm writing a perl script, and in it I want to see if I'm connected to the internet (I'm using a cable modem).
I tried ping (setting the -w option set to 1, or the -W option set to 1, or the -t option set to 1) but if I'm not connected, it hangs (I don't know how long it hangs, but it's over a half minute before I kill it. If I'm not connected, I don't want it hanging for more than a second) Ideally, I'd like a command which would come back within a second saying I'm not connected.
Also tried ftp, wget, whois... they all hang for a long time if not connected.
Are using a numeric ip address? If you are not, ping will hang much longer (though it will still return) because it first has to resolve the host name.
But even with a numeric address, it isn't going to return instantly, and you wouldn't want it to, because networks can be slow.
I'd "ping -c1" my (numeric) gateway address first. If that fails, you are definitely going nowhere. If that's on your lan, then "-w 1" is fine, but I would not use -w for anything past a local router because temporarily slow does not mean not connected.
If it succeeds, you still don't really know that you have connectivity, so I'd next try the closest thing I know - like my isp's dns or mail server. Depending on how seriously you define "connectivity", I'd then move on to checking things farther away or the things I already know I need to talk to.
Further, ping doesn't absolutely say you have any high level connectivity, so if you REALLY need to know, then you need to do more, like a lynx dump for a web page, a test ftp connection, or whatever tells you that by gum you really do have full connectivity.
You can also check the return status of the ping command. It will return 0 if it was able to ping the remote host, and 1 otherwise. This is probably more reliable, because just the face that your ethernet interface received a packet doesn't necessarily mean that you're connected (the received packet xcould've been from your gateway, for instance).