Last active
March 8, 2023 16:01
-
-
Save LuisPalacios/1c7e2e04676124de85ced92df57a1bd7 to your computer and use it in GitHub Desktop.
Norte: Comprobar conectividad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Script que verifica que la configuracion de la red es correcta, | |
# que hay conectividad con internet, prueba servicios, etc. | |
# | |
# Copyright (C) 2006 Luis Palacios | |
# | |
# Variables de trabajo | |
temporal=/tmp/temp-parchis-verifica.sh | |
# Usar las variables con "echo -e" para que interprete las secuencias \escaped... | |
NORMAL="\033[0;39m" | |
ROJO="\033[1;31m" | |
VERDE="\033[1;32m" | |
AMARILLO="\033[1;33m" | |
# Columna donde se muestra el mensaje de resultado (linea 1000, asi siempre | |
# se ensena en la ultima linea de la shell... y columna 80) | |
RESOK="\033[1000;80H[${VERDE}OK${NORMAL}]" | |
RESWARN="\033[1000;75H[${AMARILLO}warning${NORMAL}]" | |
RESERROR="\033[1000;77H[${ROJO}ERROR${NORMAL}]" | |
# Salir del programa | |
salir() { | |
rm -f $temporal | |
exit | |
} | |
# Funcion para comprobar el estado de las subinterfaces | |
# En $1 nos pasan el nombre de la interfaz | |
# En $2 el nivel de importancia que tiene (1-aviso, 2 o cualquier | |
# otro numero entonces es critico) si la interfaz no esta disponible | |
test_intf() { | |
# Get the IP Address from first argument | |
intf=$1 | |
nivel=$2 | |
echo -n "Probando interface: $intf" | |
ip link show $intf 2>/dev/null | grep UP > /dev/null 2>/dev/null | |
ret=$? | |
if [ "$ret" = "0" ] ; then | |
echo -e "${RESOK}" | |
else | |
if [ "$nivel" = "1" ]; then | |
echo -e "${RESWARN}" | |
else | |
echo -e "${RESERROR}" | |
fi | |
fi | |
} | |
# Funcion para comprobar el estado de un parámetro del Kernel | |
# En $1 nos pasan el valor que debería obtenerse para considerarse como bueno | |
# En $2 el nombre del fichero (en realidad es el parámetro del kernel) | |
test_kernel() { | |
# Get the file name to check and the desired value | |
wanted=$1 | |
kfilename=$2 | |
echo -n "Comprobando Kernel: ${kfilename}" | |
ret=`cat ${kfilename}` | |
if [ "${ret}" = "${wanted}" ] ; then | |
echo -e " (OK=${wanted}) ${RESOK}" | |
else | |
echo -e " (OK=${wanted}) ${RESERROR}" | |
fi | |
} | |
# Funcion para probar conectividad con la direccion | |
# IP que nos pasan en '$1' y mostrando detras el mensajje en '$2' | |
# En $3 el nivel de importancia que tiene (1-aviso, 2 o cualquier | |
# otro critico) si la interfaz no esta disponible | |
test_ip() { | |
# Get the IP Address from first argument | |
ip=$1 | |
txt=$2 | |
nivel=$3 | |
echo -n "Probando IP $ip: $txt ..." | |
ping -c 1 $ip > $temporal 2>/dev/null | |
ret=$? | |
if [ "$ret" = "0" ] ; then | |
ms=`cat $temporal | grep rtt | awk 'BEGIN{FS="/"};{printf $5}'` | |
echo -e "${RESOK} $ms ms" | |
else | |
if [ "$nivel" = "1" ]; then | |
echo -e "${RESWARN}" | |
else | |
echo -e "${RESERROR}" | |
fi | |
fi | |
} | |
# Funcion para probar conectividad con la direccion | |
# IP que nos pasan desde '$1' a '$2'. Muestra el mensaje de '$3'. | |
# En $4 el nivel de importancia que tiene (1-aviso, 2 o cualquier | |
# otro critico) si la interfaz no esta disponible | |
test_ip_src_dst() { | |
# Get the IP Address from first argument | |
ip_src=$1 | |
ip_dst=$2 | |
txt=$3 | |
nivel=$4 | |
echo -n "Probando IP $ip_dst: $txt ..." | |
ping -c 1 -I $ip_src $ip_dst > $temporal 2>/dev/null | |
ret=$? | |
if [ "$ret" = "0" ] ; then | |
ms=`cat $temporal | grep rtt | awk 'BEGIN{FS="/"};{printf $5}'` | |
echo -e "${RESOK} $ms ms" | |
else | |
if [ "$nivel" = "1" ]; then | |
echo -e "${RESWARN}" | |
else | |
echo -e "${RESERROR}" | |
fi | |
fi | |
} | |
# Commprobar que 'registro' nuestro dns server funciona bien | |
test_dns() { | |
# get parameters | |
ip=$1 | |
echo -n "Comprobando: DNS Server ${ip} UDP 53" | |
ret=`dig +time=1 +tries=1 parchis.org @${ip}|grep -i SOA` | |
if [ "${?}" = "0" ] ; then | |
echo -e "${RESOK}" | |
else | |
echo -e "${RESERROR}" | |
fi | |
} | |
# Funcion para probar que el DNS Server funciona bien, consulto el SOA | |
test_dns_soa() { | |
# Get the domain name | |
domainname=$1 | |
txt=$2 | |
echo -n "Comprobando: ${txt}" | |
ret=`dig +time=1 @172.26.23.3 ${domainname} | grep SOA` | |
if [ "${?}" = "0" ] ; then | |
echo -e "${RESOK}" | |
else | |
echo -e "${RESERROR}" | |
fi | |
} | |
# Comprobar conectividad con la direccion IPv6 en '$1', mostrando mensaje '$2'. | |
# En $2 el nivel de importancia que tiene (1-aviso, 2 o cualquier | |
# otro numero entonces es critico) si la interfaz no esta disponible | |
test_unit() { | |
unit=$1 | |
txt=$2 | |
nivel=$3 | |
echo -n "Unit (servicio) ${unit}: $txt ..." | |
systemctl is-active ${unit} > ${temporal} 2>/dev/null | |
ret=$? | |
if [ "$ret" = "0" ] ; then | |
echo -e "${RESOK}" | |
else | |
if [ "$nivel" = "1" ]; then | |
echo -e "${RESWARN}" | |
else | |
echo -e "${RESERROR}" | |
fi | |
fi | |
} | |
# | |
# Verificar el forwarding y RPF en el Kernel | |
# ========================================= | |
# Cargo los nombres de las interfaces | |
. /root/firewall/norte_firewall_inames.sh | |
# | |
# Verificar la conectividad en IP | |
# =============================== | |
echo | |
test_unit firewall_1_pre_network "IPTABLES (pre-net)" | |
test_unit firewall_2_post_network "IPTABLES (post-net)" | |
test_unit watch_eth_bridge_con_sur.timer "Vigilante" | |
test_unit sshd.service "SSHD" | |
# | |
# Verificar la conectividad en IP | |
# =============================== | |
test_intf lo 2 | |
test_intf ${ifWan} 2 | |
test_intf ${ifLanIPTV} 2 | |
test_intf ${ifBridgeIPTV} 2 | |
test_intf ${ifTunelSur} 2 | |
# | |
# Verificar la conectividad en IP | |
# =============================== | |
test_ip localhost "localhost (lo)" | |
test_ip 192.168.1.1 "Router de acceso a Internet" | |
test_ip 192.168.224.2 "Tunel Internet con Sur" | |
test_ip 192.168.206.2 "Tunel IPTV con Sur" | |
test_ip_src_dst 192.168.206.1 10.64.0.1 "MOVISTAR IPTV" | |
# Compruebo el forwarding | |
test_kernel 1 /proc/sys/net/ipv4/ip_forward | |
# Compruebo RPF's | |
test_kernel 0 /proc/sys/net/ipv4/conf/lo/rp_filter | |
test_kernel 0 /proc/sys/net/ipv4/conf/all/rp_filter | |
test_kernel 1 /proc/sys/net/ipv4/conf/default/rp_filter | |
test_kernel 1 /proc/sys/net/ipv4/conf/${ifWan}/rp_filter | |
test_kernel 0 /proc/sys/net/ipv4/conf/${ifLanIPTV}/rp_filter | |
test_kernel 0 /proc/sys/net/ipv4/conf/${ifBridgeIPTV}/rp_filter | |
test_kernel 1 /proc/sys/net/ipv4/conf/${ifTunelSur}/rp_filter | |
test_kernel 1 /proc/sys/net/ipv4/conf/${ifTunelSur}/forwarding | |
echo "WAN Interfaz Internet ifWan : ${ifWan} - ${ipWan}" | |
echo "LAN IPTV ifLanIPTV : ${ifLanIPTV} - ${ipLanIPTV}" | |
echo "Tunel Sur ifTunelSur : ${ifTunelSur}" | |
echo "Bridge IPTV ifBridgeIPTV : ${ifBridgeIPTV} - ${ipBridgeIPTV}" | |
echo "INTRANET : ${INTRANET}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment