book graphic unix and linux troubleshooting guide

My Troubleshooting E-Book will show you how to solve tough problems on Linux and Unix systems!







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
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


Click here to add your comments





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
171414 4,359

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


http://www.schewanick.com SCO Unix, Solaris, Linx (various), PHP, MySQL, Apache, uniBasic, dL4, Perl, System Administration and more....


http://www.cleverminds.net Need expert advice? Want a second opinion? CleverMinds is a one-stop-shop for a wide range of technology solutions. We support Unix, Linux, SCO as well as CMS, ecom, blogs, podcasts, search engines consulting and more. Contact us at web2.0@cleverminds.net 0r (617) 894-1282


UBB Computer Services Support for Openserver, Unixware and Linux. Windows integration with Unix/Linux servers. Hardware, Backup and Networking issues. Located near Sacramento CA, we provide onsite support throughout Northern CA and Nationwide via remote access. We are a SCO Authorized Partner and a Microlite BackupEdge Certified Reseller.



Twitter
o Somebody let me know when its safe to turn on the TV again - when they've finally stopped talking about football. 9:15 PM Feb 3rd 2008








Change Congress

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