Testing for network connectivity in a script

(Traditional format)

Sun Dec 19 13:50:41 2004 Testing for network connectivity in a script
Posted by Tony Lawrence
Search Keys: network

Sometimes a script needs to know if it has network or internet connectivity before it continues, or perhaps its whole purpose is the report a loss of connectivity or inability to reach specific services.


Hate these ads?

A typical response to such a problem is to use "ping" to determine if some other host is "up". That's pretty simplistic, though, and really doesn't tell the whole story.

If you really want to test connectivity, and want the script to be able to tell you where the problems are when it is lacking, you need a more procedural approach. First, ping something on your local network, using a "-c5" or even a larger count (don't use the "-w" flag here). The reason for a larger count rather than the commonly advised "-c1" is that very temporary and unimportant problems can cause single packet loss. This *shouldn't* be on your local network, but asking for more packets gives you more information about the situation if you do have this problem. Similarly, the reason not to use -w1 or -w anything (which times out after that many seconds) is because temporarily slow does not mean not connected.

Use a numeric ip address for this first test so that you aren't triggering dns name resolution. Test more than one address in case one host is down. If none of these work, you know you have serious local problems: either your nic isn't working or connected, or the rest of your network is down.

Next try the router on your lan segment, again using numeric ip addresses. If that doesn't respond, you won't be going off-network, so you can stop now.

If these tests succeed, 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.

If you have had any indications of failure, increase -c to get an idea of how bad the loss actually is. Somewhere in here I'd check with a hostname or two, to see that DNS is working.






Consider that 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. If your purpose is to specific hosts, that's all you need to know, but if your concern is general connectivity, then you need to test a range of hosts.

Your script may also want to check "ifconfig" and "netstat -i" if it is logging problems. Changes of netstat -i stats in the error columns over a short period of time probably indicates serious problems.



Comments /Blog/B1200.html
CommentsBlog1200 :

"Your script may also want to check 'ifconfig' and 'netstat -i' if it is logging problems."

Another thing to look at is "netstat -m" for a snapshot of STREAMS memory usage. This will reveal if the various networking layers have adequate resources to do their jobs. "netstat -rn" is useful if routing problems are suspected.

--BigDumbDinosaur

---December 20, 2004

Any Sample scripts for the newbies? I have some real small ones, but if someone has something more complex, it would be nice to see an example of this in use.

--BruceGarlock



---December 20, 2004

I didn't do any samples because these are so specific to what your needs are.

--TonyLawrence


Add your comments

LOD Communications, Inc.

Enter your email address for automatic notification of new posts here
(be sure to whitelist 'feedburner.com' if you use spam filtering)

Or use any RSS reader

Delivered by FeedBurner


Views for this page
Today This Week This Month This Year  Overall
3527505 4,135

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

pavatar.jpg
More:
       - Linux
       - Unix
       - Networking
       - Blog




Unix/Linux Consultants

Your ad here - $24.00 yearly!

http://www.vss3.com SCO/Caldera OpenServer, Unixware & Linux. Tarantella & Non-stop Clustering


larryi@ccamedical.com SCO OS5, Debian Linux, RedHat Linux, MySQL, Apache, AJAX development using dXport/dL4/Unibasic, Windows Connectivity, Sharing Resouces, Automation, Shell Scripting


SCO, OpenServer, UnixWare, software, servers, security, networks, installation, administration, troubleshooting, maintenance, Watchguard, firewalls, VPNs, e-mail. Visit us at http://opensystemscomputing.com and www.go2unix.com.









Change Congress


Related Posts

Publish your articles, comments, book reviews or opinions here!