Sunday, January 18, 2009

Network Troubleshooting script

#!/bin/sh# Network testing script v 1.0# (c) 2005 Javier Fernandez-Sanguino## This script will test your system's network configuration using basic# tests and providing both information (INFO messages), warnings (WARN)# and possible errors (ERR messages) by checking:# - Interface status# - Availability of configured routers, including the default route# - Proper host resolution, including DNS checks# - Proper network connectivity (the remote host can be configured, see# below)# # The script does not need special privileges to run as it does not # do any system change. It also will not fix the errors by itself.## This program is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2 of the License, or# (at your option) any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with this program; if not, write to the Free Software# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA# # You can also find a copy of the GNU General Public License at# http://www.gnu.org/licenses/licenses.html#TOCLGPL## TODO# - Works only on Linux, can this be generalised for other UNIX systems# (probably not unless rewritten in C)# - Does not check for errors properly, use -e and test intensively# so that expected errors are trapped# (specially for tools that are not available, like netcat)# - If the tools are localised to languages != english the script might # break # - Ask 'host' maintainer to implement error codes as done with # dlint# - Should be able to check if DNS server is in the same network, if # it doesn't answer to pings, check ARP in that case.# - DHCP checks?# - Other internal services tests? (LDAP if using pam...)# - Generate summary of errors in the end (pretty report?)# - Check if packets are being dropped by local firewall? (use dmesg# and look for our tests)# - Support wireless interfaces? (use iwconfig)# - Check other TODOs inline in the code

# BEGIN configuration# Configure to your needs, these values will be used when# checking DNS and Internet connectivity# DNS name to resolveCHECK_HOST=www.debian.orgCHECK_IP_ADRESS=194.109.137.218# Web server to check forCHECK_WEB_HOST=www.debian.orgCHECK_WEB_PORT=80export CHECK_HOST CHECK_IP_ADRESS CHECK_WEB_HOST CHECK_WEB_PORT# END configuration

# Extract the interface of our default route

defaultif=`netstat -nr |grep ^0.0.0.0 | awk '{print $8}' | head -1`defaultroutes=`netstat -nr |grep ^0.0.0.0 | wc -l`if [ -z "$defaultif" ] ; then defaultif=none echo "WARN: This system does not have a default route"elif [ "$defaultroutes" -gt 1 ] ; then echo "WARN: This system has more than one default route"else echo "INFO: This system has exactly one default route"fi

# TODO: checks could be conditioned, i.e. if there is no proper# interface setup don't bother with DNS and don't do some Inet checks# if DNS is not setup properlycheck_localcheck_netifcheck_dnscheck_conn

exit 0

Wireless Troubleshooting guide can also be scriptedhttp://www.ubuntugeek.com/how-to-troubleshoot-wireless-network-connection-in-ubuntu.html