[RFC-ADN-01] Normalizar nomenclatura de proyectos
- Directorios: PascalCase (p2601_dasuten → P2601_Dasuten) - Planes: numeración pura (P2601_6.1.A → P2601.06.01) - Sin caracteres especiales en nombres de archivo - 07_proyectos.md: convención RFC-ADN-01 integrada, P2604/P2605 agregados - evento:listar: nueva opción --detalle para descripciones completas
This commit is contained in:
@@ -0,0 +1,399 @@
|
||||
# Script de diagnóstico de red local para pc-dasu0
|
||||
# Uso: .\Diagnose-LocalNetwork.ps1 [-InterfaceAlias "Ethernet"] [-Detailed $true]
|
||||
|
||||
param(
|
||||
[string]$InterfaceAlias = "Ethernet",
|
||||
[bool]$Detailed = $true,
|
||||
[string]$LogPath = "C:\Logs\NetworkDiagnostic"
|
||||
)
|
||||
|
||||
# Configuración inicial
|
||||
$ErrorActionPreference = "Stop"
|
||||
$Timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
|
||||
$LogFile = Join-Path $LogPath "NetworkDiagnostic_$Timestamp.log"
|
||||
$ReportFile = Join-Path $LogPath "NetworkReport_$Timestamp.md"
|
||||
|
||||
# Crear directorio de logs si no existe
|
||||
if (-not (Test-Path $LogPath)) {
|
||||
New-Item -ItemType Directory -Path $LogPath -Force | Out-Null
|
||||
}
|
||||
|
||||
# Funciones de logging
|
||||
function Write-Log {
|
||||
param([string]$Message, [string]$Level = "INFO")
|
||||
|
||||
$FormattedMessage = "[$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')] [$Level] $Message"
|
||||
|
||||
switch ($Level) {
|
||||
"ERROR" { Write-Host $FormattedMessage -ForegroundColor Red }
|
||||
"WARNING" { Write-Host $FormattedMessage -ForegroundColor Yellow }
|
||||
"SUCCESS" { Write-Host $FormattedMessage -ForegroundColor Green }
|
||||
default { Write-Host $FormattedMessage -ForegroundColor Cyan }
|
||||
}
|
||||
|
||||
$FormattedMessage | Out-File -FilePath $LogFile -Append
|
||||
}
|
||||
|
||||
function Write-Report {
|
||||
param([string]$Content)
|
||||
$Content | Out-File -FilePath $ReportFile -Append
|
||||
}
|
||||
|
||||
function Test-Command {
|
||||
param([string]$Command)
|
||||
try {
|
||||
Get-Command $Command -ErrorAction Stop | Out-Null
|
||||
return $true
|
||||
} catch {
|
||||
return $false
|
||||
}
|
||||
}
|
||||
|
||||
# Inicio del diagnóstico
|
||||
Write-Log "========================================"
|
||||
Write-Log " DIAGNÓSTICO DE RED LOCAL - pc-dasu0"
|
||||
Write-Log "========================================"
|
||||
Write-Log ""
|
||||
|
||||
Write-Report "# Reporte de Diagnóstico de Red Local"
|
||||
Write-Report "Fecha: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')"
|
||||
Write-Report "Hostname: $env:COMPUTERNAME"
|
||||
Write-Report "Usuario: $env:USERNAME"
|
||||
Write-Report ""
|
||||
|
||||
# 1. Verificar adaptador de red
|
||||
Write-Log "1. Verificando adaptador de red '$InterfaceAlias'..."
|
||||
Write-Report "## 1. Información del Adaptador de Red"
|
||||
|
||||
try {
|
||||
$NetworkAdapter = Get-NetAdapter -Name $InterfaceAlias -ErrorAction Stop
|
||||
|
||||
Write-Log " Adaptador encontrado: $($NetworkAdapter.Name)"
|
||||
Write-Log " Estado: $($NetworkAdapter.Status)"
|
||||
Write-Log " Velocidad: $($NetworkAdapter.LinkSpeed)"
|
||||
|
||||
Write-Report "### Adaptador: $($NetworkAdapter.Name)"
|
||||
Write-Report "- Estado: $($NetworkAdapter.Status)"
|
||||
Write-Report "- Velocidad: $($NetworkAdapter.LinkSpeed)"
|
||||
Write-Report "- MAC Address: $($NetworkAdapter.MacAddress)"
|
||||
Write-Report "- Interface Description: $($NetworkAdapter.InterfaceDescription)"
|
||||
Write-Report ""
|
||||
|
||||
if ($NetworkAdapter.Status -ne "Up") {
|
||||
Write-Log " ADVERTENCIA: El adaptador no está activo" -Level "WARNING"
|
||||
}
|
||||
|
||||
} catch {
|
||||
Write-Log " ERROR: No se encontró el adaptador '$InterfaceAlias'" -Level "ERROR"
|
||||
Write-Log " Adaptadores disponibles:"
|
||||
Get-NetAdapter | ForEach-Object {
|
||||
Write-Log " - $($_.Name): $($_.Status)"
|
||||
}
|
||||
Write-Report "ERROR: Adaptador '$InterfaceAlias' no encontrado"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 2. Obtener configuración IP
|
||||
Write-Log "2. Obteniendo configuración IP..."
|
||||
Write-Report "## 2. Configuración IP"
|
||||
|
||||
try {
|
||||
$IPConfiguration = Get-NetIPConfiguration -InterfaceAlias $InterfaceAlias -ErrorAction Stop
|
||||
|
||||
Write-Log " IPv4 Address: $($IPConfiguration.IPv4Address.IPAddress)"
|
||||
Write-Log " Subnet Mask: $($IPConfiguration.IPv4Address.PrefixLength)"
|
||||
Write-Log " Gateway: $($IPConfiguration.IPv4DefaultGateway.NextHop)"
|
||||
|
||||
Write-Report "### Configuración IPv4"
|
||||
Write-Report "- Dirección IP: $($IPConfiguration.IPv4Address.IPAddress)"
|
||||
Write-Report "- Prefijo: /$($IPConfiguration.IPv4Address.PrefixLength)"
|
||||
Write-Report "- Gateway: $($IPConfiguration.IPv4DefaultGateway.NextHop)"
|
||||
Write-Report ""
|
||||
|
||||
# Calcular subred
|
||||
$IPAddress = $IPConfiguration.IPv4Address.IPAddress
|
||||
$PrefixLength = $IPConfiguration.IPv4Address.PrefixLength
|
||||
$SubnetMask = [System.Net.IPAddress]::Parse(([System.Net.IPAddress]::Parse("255.255.255.255").GetAddressBytes() |
|
||||
ForEach-Object { $_ -shl (32 - $PrefixLength) }))
|
||||
|
||||
$NetworkAddress = [System.Net.IPAddress]::new((
|
||||
[System.Net.IPAddress]::Parse($IPAddress).GetAddressBytes() |
|
||||
ForEach-Object { $_ -band $SubnetMask.GetAddressBytes()[$i]; $i++ }))
|
||||
|
||||
$Subnet = "$NetworkAddress/$PrefixLength"
|
||||
Write-Log " Subred calculada: $Subnet"
|
||||
Write-Report "- Subred: $Subnet"
|
||||
Write-Report ""
|
||||
|
||||
# Servidores DNS
|
||||
Write-Log " Servidores DNS:"
|
||||
$DNSServers = $IPConfiguration.DNSServer.ServerAddresses
|
||||
if ($DNSServers) {
|
||||
$i = 1
|
||||
foreach ($DNS in $DNSServers) {
|
||||
Write-Log " $i. $DNS"
|
||||
Write-Report "- DNS $($i): $DNS"
|
||||
$i++
|
||||
}
|
||||
} else {
|
||||
Write-Log " ADVERTENCIA: No hay servidores DNS configurados" -Level "WARNING"
|
||||
Write-Report "- DNS: No configurado"
|
||||
}
|
||||
|
||||
Write-Report ""
|
||||
|
||||
} catch {
|
||||
Write-Log " ERROR: No se pudo obtener configuración IP" -Level "ERROR"
|
||||
Write-Report "ERROR: No se pudo obtener configuración IP"
|
||||
}
|
||||
|
||||
# 3. Probar conectividad
|
||||
Write-Log "3. Probando conectividad de red..."
|
||||
Write-Report "## 3. Pruebas de Conectividad"
|
||||
|
||||
# Gateway
|
||||
$Gateway = $IPConfiguration.IPv4DefaultGateway.NextHop
|
||||
if ($Gateway) {
|
||||
Write-Log " Probando gateway $Gateway..."
|
||||
$GatewayTest = Test-NetConnection -ComputerName $Gateway -InformationLevel Quiet
|
||||
|
||||
if ($GatewayTest) {
|
||||
Write-Log " ✅ Gateway alcanzable" -Level "SUCCESS"
|
||||
Write-Report "- Gateway ($Gateway): ✅ Alcanzable"
|
||||
} else {
|
||||
Write-Log " ❌ Gateway no alcanzable" -Level "ERROR"
|
||||
Write-Report "- Gateway ($Gateway): ❌ No alcanzable"
|
||||
}
|
||||
} else {
|
||||
Write-Log " ADVERTENCIA: No hay gateway configurado" -Level "WARNING"
|
||||
Write-Report "- Gateway: No configurado"
|
||||
}
|
||||
|
||||
# Internet
|
||||
Write-Log " Probando conectividad a internet (8.8.8.8)..."
|
||||
$InternetTest = Test-NetConnection -ComputerName "8.8.8.8" -InformationLevel Quiet -WarningAction SilentlyContinue
|
||||
|
||||
if ($InternetTest) {
|
||||
Write-Log " ✅ Internet alcanzable" -Level "SUCCESS"
|
||||
Write-Report "- Internet (8.8.8.8): ✅ Alcanzable"
|
||||
} else {
|
||||
Write-Log " ❌ Internet no alcanzable" -Level "ERROR"
|
||||
Write-Report "- Internet (8.8.8.8): ❌ No alcanzable"
|
||||
}
|
||||
|
||||
# srv-dasu (si se conoce la IP)
|
||||
Write-Log " Probando conectividad a srv-dasu (192.168.1.205)..."
|
||||
$SrvDasuTest = Test-NetConnection -ComputerName "192.168.1.205" -InformationLevel Quiet -WarningAction SilentlyContinue
|
||||
|
||||
if ($SrvDasuTest) {
|
||||
Write-Log " ✅ srv-dasu alcanzable localmente" -Level "SUCCESS"
|
||||
Write-Report "- srv-dasu (192.168.1.205): ✅ Alcanzable"
|
||||
} else {
|
||||
Write-Log " ⚠️ srv-dasu no alcanzable localmente" -Level "WARNING"
|
||||
Write-Report "- srv-dasu (192.168.1.205): ⚠️ No alcanzable"
|
||||
}
|
||||
|
||||
Write-Report ""
|
||||
|
||||
# 4. Verificar DNS
|
||||
Write-Log "4. Verificando resolución DNS..."
|
||||
Write-Report "## 4. Pruebas de DNS"
|
||||
|
||||
# Resolución de dominio DASUTEN
|
||||
Write-Log " Probando resolución de dc-dasuten.dasuten.utnlr..."
|
||||
try {
|
||||
$DNSResult = Resolve-DnsName -Name "dc-dasuten.dasuten.utnlr" -ErrorAction Stop
|
||||
|
||||
if ($DNSResult.IPAddress) {
|
||||
Write-Log " ✅ DNS resuelve a: $($DNSResult.IPAddress)" -Level "SUCCESS"
|
||||
Write-Report "- dc-dasuten.dasuten.utnlr: ✅ $($DNSResult.IPAddress)"
|
||||
} else {
|
||||
Write-Log " ❌ DNS no devolvió IP" -Level "ERROR"
|
||||
Write-Report "- dc-dasuten.dasuten.utnlr: ❌ Sin respuesta"
|
||||
}
|
||||
} catch {
|
||||
Write-Log " ❌ Error en resolución DNS: $_" -Level "ERROR"
|
||||
Write-Report "- dc-dasuten.dasuten.utnlr: ❌ Error: $_"
|
||||
}
|
||||
|
||||
# Resolución inversa
|
||||
Write-Log " Probando resolución inversa de 10.0.100.10..."
|
||||
try {
|
||||
$ReverseDNS = Resolve-DnsName -Name "10.0.100.10" -Type PTR -ErrorAction Stop
|
||||
|
||||
if ($ReverseDNS.NameHost) {
|
||||
Write-Log " ✅ Resolución inversa: $($ReverseDNS.NameHost)" -Level "SUCCESS"
|
||||
Write-Report "- 10.0.100.10 (PTR): ✅ $($ReverseDNS.NameHost)"
|
||||
}
|
||||
} catch {
|
||||
Write-Log " ⚠️ No se pudo resolver PTR para 10.0.100.10" -Level "WARNING"
|
||||
Write-Report "- 10.0.100.10 (PTR): ⚠️ No resuelto"
|
||||
}
|
||||
|
||||
Write-Report ""
|
||||
|
||||
# 5. Verificar puertos críticos del dominio
|
||||
Write-Log "5. Verificando puertos críticos del dominio..."
|
||||
Write-Report "## 5. Puertos del Dominio DASUTEN"
|
||||
|
||||
$DomainController = "10.0.100.10"
|
||||
$CriticalPorts = @(
|
||||
@{Port=389; Service="LDAP"},
|
||||
@{Port=88; Service="Kerberos"},
|
||||
@{Port=445; Service="SMB"},
|
||||
@{Port=53; Service="DNS"},
|
||||
@{Port=135; Service="RPC"},
|
||||
@{Port=636; Service="LDAPS"}
|
||||
)
|
||||
|
||||
foreach ($PortInfo in $CriticalPorts) {
|
||||
Write-Log " Probando puerto $($PortInfo.Port) ($($PortInfo.Service))..."
|
||||
|
||||
$PortTest = Test-NetConnection -ComputerName $DomainController -Port $PortInfo.Port -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
|
||||
|
||||
if ($PortTest.TcpTestSucceeded) {
|
||||
Write-Log " ✅ Puerto $($PortInfo.Port) abierto" -Level "SUCCESS"
|
||||
Write-Report "- $($PortInfo.Service) (puerto $($PortInfo.Port)): ✅ Abierto"
|
||||
} else {
|
||||
Write-Log " ❌ Puerto $($PortInfo.Port) cerrado" -Level "ERROR"
|
||||
Write-Report "- $($PortInfo.Service) (puerto $($PortInfo.Port)): ❌ Cerrado"
|
||||
}
|
||||
}
|
||||
|
||||
Write-Report ""
|
||||
|
||||
# 6. Verificar Tailscale
|
||||
Write-Log "6. Verificando estado de Tailscale..."
|
||||
Write-Report "## 6. Estado de Tailscale"
|
||||
|
||||
if (Test-Command "tailscale") {
|
||||
try {
|
||||
$TailscaleStatus = & tailscale status --json 2>$null | ConvertFrom-Json
|
||||
|
||||
if ($TailscaleStatus.Self.TailscaleIPs) {
|
||||
$TailscaleIP = $TailscaleStatus.Self.TailscaleIPs[0]
|
||||
Write-Log " ✅ Tailscale conectado: $TailscaleIP" -Level "SUCCESS"
|
||||
Write-Report "- Estado: ✅ Conectado"
|
||||
Write-Report "- IP Tailscale: $TailscaleIP"
|
||||
|
||||
# Verificar peers
|
||||
$PeerCount = ($TailscaleStatus.Peer | Measure-Object).Count
|
||||
Write-Log " Peers conectados: $PeerCount"
|
||||
Write-Report "- Peers conectados: $PeerCount"
|
||||
} else {
|
||||
Write-Log " ⚠️ Tailscale instalado pero no conectado" -Level "WARNING"
|
||||
Write-Report "- Estado: ⚠️ Instalado pero no conectado"
|
||||
}
|
||||
} catch {
|
||||
Write-Log " ⚠️ No se pudo obtener estado de Tailscale" -Level "WARNING"
|
||||
Write-Report "- Estado: ⚠️ Error al obtener estado"
|
||||
}
|
||||
} else {
|
||||
Write-Log " ⚠️ Tailscale no está instalado" -Level "WARNING"
|
||||
Write-Report "- Estado: ⚠️ No instalado"
|
||||
}
|
||||
|
||||
Write-Report ""
|
||||
|
||||
# 7. Escanear red local (opcional)
|
||||
if ($Detailed) {
|
||||
Write-Log "7. Escaneando dispositivos en red local..."
|
||||
Write-Report "## 7. Dispositivos en Red Local"
|
||||
|
||||
try {
|
||||
# Usar ARP para detectar dispositivos
|
||||
$ARPTable = arp -a | Select-String "dynamic" | ForEach-Object {
|
||||
$Line = $_.ToString().Trim()
|
||||
$Parts = $Line -split '\s+'
|
||||
|
||||
[PSCustomObject]@{
|
||||
IP = $Parts[0]
|
||||
MAC = $Parts[1]
|
||||
Type = $Parts[2]
|
||||
}
|
||||
}
|
||||
|
||||
$DeviceCount = ($ARPTable | Measure-Object).Count
|
||||
Write-Log " Dispositivos detectados en ARP: $DeviceCount"
|
||||
Write-Report "- Dispositivos en tabla ARP: $DeviceCount"
|
||||
|
||||
if ($DeviceCount -gt 0) {
|
||||
Write-Report ""
|
||||
Write-Report "### Primeros 10 dispositivos:"
|
||||
$ARPTable | Select-Object -First 10 | ForEach-Object {
|
||||
Write-Report "- $($_.IP) ($($_.MAC))"
|
||||
}
|
||||
}
|
||||
|
||||
} catch {
|
||||
Write-Log " ⚠️ No se pudo escanear red local" -Level "WARNING"
|
||||
Write-Report "- Escaneo: ⚠️ No disponible"
|
||||
}
|
||||
|
||||
Write-Report ""
|
||||
}
|
||||
|
||||
# 8. Generar recomendaciones
|
||||
Write-Log "8. Generando recomendaciones..."
|
||||
Write-Report "## 8. Recomendaciones para Comunicación Local"
|
||||
|
||||
$BaseNetwork = $IPAddress -replace '\.\d+$', ''
|
||||
$RecommendedSrvIP = "$BaseNetwork.205"
|
||||
$RecommendedPcIP = "$BaseNetwork.100"
|
||||
|
||||
Write-Report "### Configuración recomendada para comunicación local:"
|
||||
Write-Report ""
|
||||
Write-Report "1. **IPs estáticas locales:**"
|
||||
Write-Report " - srv-dasu: $RecommendedSrvIP/24"
|
||||
Write-Report " - pc-dasu0: $RecommendedPcIP/24"
|
||||
Write-Report ""
|
||||
Write-Report "2. **Configuración de red en pc-dasu0:**"
|
||||
Write-Report " - IP: $RecommendedPcIP"
|
||||
Write-Report " - Máscara: 255.255.255.0"
|
||||
Write-Report " - Gateway: $Gateway"
|
||||
Write-Report " - DNS Primario: 10.0.100.10 (dc-dasuten)"
|
||||
Write-Report " - DNS Secundario: 8.8.8.8"
|
||||
Write-Report " - Suffix DNS: dasuten.utnlr"
|
||||
Write-Report ""
|
||||
Write-Report "3. **Verificaciones previas:**"
|
||||
Write-Report " - Confirmar que $RecommendedSrvIP y $RecommendedPcIP no están en uso"
|
||||
Write-Report " - Verificar firewall (permitir ICMP, puertos 389, 88, 445, 53)"
|
||||
Write-Report " - Mantener Tailscale activo como respaldo"
|
||||
Write-Report ""
|
||||
Write-Report "4. **Comandos de prueba post-configuración:**"
|
||||
Write-Report " ```powershell"
|
||||
Write-Report " # Probar conectividad local"
|
||||
Write-Report " Test-NetConnection $RecommendedSrvIP"
|
||||
Write-Report " "
|
||||
Write-Report " # Probar resolución DNS"
|
||||
Write-Report " Resolve-DnsName dc-dasuten.dasuten.utnlr"
|
||||
Write-Report " "
|
||||
Write-Report " # Probar puertos del dominio"
|
||||
Write-Report " Test-NetConnection 10.0.100.10 -Port 389"
|
||||
Write-Report " ```"
|
||||
Write-Report ""
|
||||
|
||||
# 9. Resumen final
|
||||
Write-Log "9. Generando resumen final..."
|
||||
Write-Report "## 9. Resumen del Diagnóstico"
|
||||
|
||||
Write-Report "- **Adaptador de red**: $($NetworkAdapter.Name) ($($NetworkAdapter.Status))"
|
||||
Write-Report "- **IP Configurada**: $IPAddress/$PrefixLength"
|
||||
Write-Report "- **Gateway**: $(if($Gateway) {$Gateway} else {"No configurado"})"
|
||||
Write-Report "- **Subred**: $Subnet"
|
||||
Write-Report "- **DNS Servers**: $(if($DNSServers) {$DNSServers -join ', '} else {"No configurado"})"
|
||||
Write-Report "- **Internet**: $(if($InternetTest) {"✅ Alcanzable"} else {"❌ No alcanzable"})"
|
||||
Write-Report "- **srv-dasu local**: $(if($SrvDasuTest) {"✅ Alcanzable"} else {"⚠️ No alcanzable"})"
|
||||
Write-Report "- **Tailscale**: $(if(Test-Command "tailscale") {"✅ Instalado"} else {"⚠️ No instalado"})"
|
||||
Write-Report ""
|
||||
Write-Report "### Archivos generados:"
|
||||
Write-Report "- Log detallado: $LogFile"
|
||||
Write-Report "- Reporte completo: $ReportFile"
|
||||
Write-Report ""
|
||||
Write-Report "### Próximos pasos:"
|
||||
Write-Report "1. Si la conectividad local falla, verificar configuración del router ISP"
|
||||
Write-Report "2. Configurar IPs estáticas según recomendaciones"
|
||||
Write-Report "3. Probar AD-Join después de configurar comunicación local"
|
||||
Write-Report "4. Mantener Tailscale como respaldo para acceso remoto"
|
||||
Write-Report ""
|
||||
Write-Report "*Diagnóstico completado: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')*"
|
||||
@@ -0,0 +1,337 @@
|
||||
#!/bin/bash
|
||||
# Script de diagnóstico automático para red local
|
||||
# Uso: ./diagnostico_red_local.sh [interface]
|
||||
# Ejemplo: ./diagnostico_red_local.sh vmbr0
|
||||
|
||||
set -e
|
||||
|
||||
# Colores para output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Variables
|
||||
INTERFACE="${1:-vmbr0}"
|
||||
LOG_FILE="/tmp/diagnostico_red_local_$(date +%Y%m%d_%H%M%S).log"
|
||||
REPORT_FILE="/tmp/reporte_red_local_$(date +%Y%m%d_%H%M%S).md"
|
||||
|
||||
# Funciones de utilidad
|
||||
log() {
|
||||
echo -e "${BLUE}[INFO]${NC} $1" | tee -a "$LOG_FILE"
|
||||
}
|
||||
|
||||
success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1" | tee -a "$LOG_FILE"
|
||||
}
|
||||
|
||||
warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1" | tee -a "$LOG_FILE"
|
||||
}
|
||||
|
||||
error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1" | tee -a "$LOG_FILE"
|
||||
}
|
||||
|
||||
check_dependencies() {
|
||||
local deps=("ip" "ping" "awk" "grep" "tee")
|
||||
local missing=()
|
||||
|
||||
for dep in "${deps[@]}"; do
|
||||
if ! command -v "$dep" &> /dev/null; then
|
||||
missing+=("$dep")
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ${#missing[@]} -gt 0 ]; then
|
||||
error "Dependencias faltantes: ${missing[*]}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Dependencias opcionales
|
||||
if command -v "nmap" &> /dev/null; then
|
||||
HAS_NMAP=true
|
||||
else
|
||||
HAS_NMAP=false
|
||||
warning "nmap no encontrado. El escaneo de red será limitado."
|
||||
fi
|
||||
|
||||
if command -v "jq" &> /dev/null; then
|
||||
HAS_JQ=true
|
||||
else
|
||||
HAS_JQ=false
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
check_interface() {
|
||||
if ! ip link show "$INTERFACE" &> /dev/null; then
|
||||
error "Interfaz $INTERFACE no encontrada"
|
||||
echo "Interfaces disponibles:"
|
||||
ip link show | awk -F': ' '/^[0-9]+:/ {print $2}' | grep -v lo
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ "$(cat /sys/class/net/"$INTERFACE"/operstate 2>/dev/null)" != "up" ]; then
|
||||
warning "Interfaz $INTERFACE no está activa (operstate: $(cat /sys/class/net/"$INTERFACE"/operstate 2>/dev/null))"
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
get_interface_info() {
|
||||
log "Obteniendo información de la interfaz $INTERFACE..."
|
||||
|
||||
echo "=== INFORMACIÓN DE INTERFAZ ===" | tee -a "$REPORT_FILE"
|
||||
ip addr show "$INTERFACE" | tee -a "$REPORT_FILE"
|
||||
echo "" | tee -a "$REPORT_FILE"
|
||||
|
||||
# Extraer IPs configuradas
|
||||
IPS=$(ip addr show "$INTERFACE" | awk '/inet / {print $2}')
|
||||
if [ -z "$IPS" ]; then
|
||||
warning "No hay IPs configuradas en $INTERFACE"
|
||||
else
|
||||
success "IPs configuradas:"
|
||||
echo "$IPS" | while read -r ip; do
|
||||
echo " - $ip"
|
||||
done | tee -a "$REPORT_FILE"
|
||||
fi
|
||||
}
|
||||
|
||||
get_routing_info() {
|
||||
log "Obteniendo información de enrutamiento..."
|
||||
|
||||
echo "=== TABLA DE RUTAS ===" | tee -a "$REPORT_FILE"
|
||||
ip route show | tee -a "$REPORT_FILE"
|
||||
echo "" | tee -a "$REPORT_FILE"
|
||||
|
||||
# Detectar gateway predeterminado
|
||||
DEFAULT_GW=$(ip route show default | awk '/default/ {print $3}')
|
||||
if [ -n "$DEFAULT_GW" ]; then
|
||||
success "Gateway predeterminado: $DEFAULT_GW"
|
||||
echo "Gateway: $DEFAULT_GW" | tee -a "$REPORT_FILE"
|
||||
|
||||
# Probar conectividad al gateway
|
||||
log "Probando conectividad al gateway $DEFAULT_GW..."
|
||||
if ping -c 3 -W 2 "$DEFAULT_GW" &> /dev/null; then
|
||||
success "Gateway alcanzable"
|
||||
echo "Gateway alcanzable: Sí" | tee -a "$REPORT_FILE"
|
||||
else
|
||||
warning "Gateway no alcanzable"
|
||||
echo "Gateway alcanzable: No" | tee -a "$REPORT_FILE"
|
||||
fi
|
||||
else
|
||||
warning "No se encontró gateway predeterminado"
|
||||
echo "Gateway: No encontrado" | tee -a "$REPORT_FILE"
|
||||
fi
|
||||
|
||||
# Detectar subred local
|
||||
LOCAL_SUBNET=$(ip route show | grep "link src" | awk '{print $1}' | head -1)
|
||||
if [ -n "$LOCAL_SUBNET" ]; then
|
||||
success "Subred local detectada: $LOCAL_SUBNET"
|
||||
echo "Subred local: $LOCAL_SUBNET" | tee -a "$REPORT_FILE"
|
||||
else
|
||||
warning "No se pudo detectar subred local"
|
||||
echo "Subred local: No detectada" | tee -a "$REPORT_FILE"
|
||||
fi
|
||||
}
|
||||
|
||||
check_dhcp_info() {
|
||||
log "Verificando información DHCP..."
|
||||
|
||||
echo "=== INFORMACIÓN DHCP ===" | tee -a "$REPORT_FILE"
|
||||
|
||||
# Verificar archivos de lease DHCP
|
||||
DHCP_FILES=("/var/lib/dhcp/dhclient.leases" "/var/lib/dhclient/dhclient.leases")
|
||||
for file in "${DHCP_FILES[@]}"; do
|
||||
if [ -f "$file" ]; then
|
||||
log "Analizando $file..."
|
||||
if grep -q "interface.*$INTERFACE" "$file" 2>/dev/null; then
|
||||
success "Se encontraron leases DHCP para $INTERFACE"
|
||||
echo "Archivo DHCP: $file" | tee -a "$REPORT_FILE"
|
||||
|
||||
# Extraer información relevante
|
||||
grep -A10 -B2 "interface.*$INTERFACE" "$file" | \
|
||||
grep -E "(lease|starts|ends|option|fixed-address)" | \
|
||||
head -20 | tee -a "$REPORT_FILE"
|
||||
break
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if ! grep -q "Archivo DHCP:" "$REPORT_FILE"; then
|
||||
warning "No se encontraron leases DHCP para $INTERFACE"
|
||||
echo "DHCP: No se encontraron leases" | tee -a "$REPORT_FILE"
|
||||
fi
|
||||
|
||||
echo "" | tee -a "$REPORT_FILE"
|
||||
}
|
||||
|
||||
scan_local_network() {
|
||||
if [ -z "$LOCAL_SUBNET" ]; then
|
||||
warning "No se puede escanear red local (subred no detectada)"
|
||||
return 1
|
||||
fi
|
||||
|
||||
log "Escaneando red local $LOCAL_SUBNET..."
|
||||
|
||||
echo "=== ESCANEO DE RED LOCAL ===" | tee -a "$REPORT_FILE"
|
||||
|
||||
if [ "$HAS_NMAP" = true ]; then
|
||||
# Escaneo rápido con nmap
|
||||
log "Ejecutando escaneo rápido con nmap..."
|
||||
nmap -sn "$LOCAL_SUBNET" 2>/dev/null | \
|
||||
grep "Nmap scan report" | \
|
||||
head -20 | \
|
||||
tee -a "$REPORT_FILE"
|
||||
|
||||
# Contar dispositivos
|
||||
DEVICE_COUNT=$(nmap -sn "$LOCAL_SUBNET" 2>/dev/null | grep "Nmap scan report" | wc -l)
|
||||
success "Dispositivos detectados: $DEVICE_COUNT"
|
||||
echo "Total dispositivos: $DEVICE_COUNT" | tee -a "$REPORT_FILE"
|
||||
else
|
||||
# Método alternativo usando ping y arp
|
||||
warning "Usando método básico de detección (sin nmap)..."
|
||||
|
||||
# Ping a broadcast (puede no funcionar en todas las redes)
|
||||
log "Probando detección básica..."
|
||||
ping -c 2 -b "$(echo "$LOCAL_SUBNET" | cut -d'/' -f1 | sed 's/0$/255/')" &> /dev/null || true
|
||||
|
||||
# Mostrar tabla ARP
|
||||
ip neigh show | grep -v "FAILED" | \
|
||||
head -20 | \
|
||||
tee -a "$REPORT_FILE"
|
||||
|
||||
DEVICE_COUNT=$(ip neigh show | grep -v "FAILED" | wc -l)
|
||||
echo "Dispositivos en tabla ARP: $DEVICE_COUNT" | tee -a "$REPORT_FILE"
|
||||
fi
|
||||
|
||||
echo "" | tee -a "$REPORT_FILE"
|
||||
}
|
||||
|
||||
check_tailscale() {
|
||||
log "Verificando estado de Tailscale..."
|
||||
|
||||
echo "=== ESTADO TAILSCALE ===" | tee -a "$REPORT_FILE"
|
||||
|
||||
if command -v tailscale &> /dev/null; then
|
||||
tailscale status 2>/dev/null | tee -a "$REPORT_FILE"
|
||||
|
||||
# Extraer IP de Tailscale
|
||||
TAILSCALE_IP=$(tailscale status --json 2>/dev/null | \
|
||||
$([ "$HAS_JQ" = true ] && echo "jq -r '.Self.TailscaleIPs[0]'" || echo "grep -oE '100\.[0-9]+\.[0-9]+\.[0-9]+' | head -1"))
|
||||
|
||||
if [ -n "$TAILSCALE_IP" ]; then
|
||||
success "Tailscale IP: $TAILSCALE_IP"
|
||||
echo "IP Tailscale: $TAILSCALE_IP" | tee -a "$REPORT_FILE"
|
||||
else
|
||||
warning "Tailscale no parece estar conectado"
|
||||
echo "Tailscale: No conectado" | tee -a "$REPORT_FILE"
|
||||
fi
|
||||
else
|
||||
warning "Tailscale no está instalado"
|
||||
echo "Tailscale: No instalado" | tee -a "$REPORT_FILE"
|
||||
fi
|
||||
|
||||
echo "" | tee -a "$REPORT_FILE"
|
||||
}
|
||||
|
||||
generate_recommendations() {
|
||||
log "Generando recomendaciones..."
|
||||
|
||||
echo "=== RECOMENDACIONES ===" | tee -a "$REPORT_FILE"
|
||||
|
||||
# Recomendación de IP local
|
||||
if [ -n "$LOCAL_SUBNET" ]; then
|
||||
BASE_NET=$(echo "$LOCAL_SUBNET" | cut -d'/' -f1 | cut -d'.' -f1-3)
|
||||
|
||||
echo "Para configuración local entre srv-dasu y pc-dasu0:" | tee -a "$REPORT_FILE"
|
||||
echo "" | tee -a "$REPORT_FILE"
|
||||
echo "1. **IPs recomendadas (fuera de rango DHCP común):**" | tee -a "$REPORT_FILE"
|
||||
echo " - srv-dasu: ${BASE_NET}.205/24" | tee -a "$REPORT_FILE"
|
||||
echo " - pc-dasu0: ${BASE_NET}.100/24" | tee -a "$REPORT_FILE"
|
||||
echo "" | tee -a "$REPORT_FILE"
|
||||
echo "2. **Configuración de red:**" | tee -a "$REPORT_FILE"
|
||||
echo " - Gateway: $(echo "$DEFAULT_GW" || echo "[gateway-del-router]")" | tee -a "$REPORT_FILE"
|
||||
echo " - Máscara: 255.255.255.0 (/24)" | tee -a "$REPORT_FILE"
|
||||
echo " - DNS Primario: 10.0.100.10 (dc-dasuten)" | tee -a "$REPORT_FILE"
|
||||
echo " - DNS Secundario: 8.8.8.8" | tee -a "$REPORT_FILE"
|
||||
echo "" | tee -a "$REPORT_FILE"
|
||||
echo "3. **Verificaciones previas:**" | tee -a "$REPORT_FILE"
|
||||
echo " - Confirmar que ${BASE_NET}.205 y ${BASE_NET}.100 no están en uso" | tee -a "$REPORT_FILE"
|
||||
echo " - Verificar que el firewall permite ICMP y puertos necesarios" | tee -a "$REPORT_FILE"
|
||||
echo " - Tailscale debe permanecer activo como respaldo" | tee -a "$REPORT_FILE"
|
||||
else
|
||||
echo "No se pudo generar recomendaciones específicas (subred no detectada)" | tee -a "$REPORT_FILE"
|
||||
echo "" | tee -a "$REPORT_FILE"
|
||||
echo "Recomendaciones generales:" | tee -a "$REPORT_FILE"
|
||||
echo "1. Identificar manualmente la subred del router ISP" | tee -a "$REPORT_FILE"
|
||||
echo "2. Usar IPs estáticas fuera del rango DHCP del router" | tee -a "$REPORT_FILE"
|
||||
echo "3. Mantener Tailscale como ruta de failover" | tee -a "$REPORT_FILE"
|
||||
fi
|
||||
|
||||
echo "" | tee -a "$REPORT_FILE"
|
||||
}
|
||||
|
||||
generate_summary() {
|
||||
echo "=== RESUMEN DEL DIAGNÓSTICO ===" | tee -a "$REPORT_FILE"
|
||||
echo "Fecha: $(date)" | tee -a "$REPORT_FILE"
|
||||
echo "Hostname: $(hostname)" | tee -a "$REPORT_FILE"
|
||||
echo "Interfaz analizada: $INTERFACE" | tee -a "$REPORT_FILE"
|
||||
echo "Estado interfaz: $(cat /sys/class/net/"$INTERFACE"/operstate 2>/dev/null || echo "desconocido")" | tee -a "$REPORT_FILE"
|
||||
echo "Gateway: ${DEFAULT_GW:-No detectado}" | tee -a "$REPORT_FILE"
|
||||
echo "Subred local: ${LOCAL_SUBNET:-No detectada}" | tee -a "$REPORT_FILE"
|
||||
echo "Tailscale: $(if command -v tailscale &> /dev/null; then echo "Instalado"; else echo "No instalado"; fi)" | tee -a "$REPORT_FILE"
|
||||
echo "" | tee -a "$REPORT_FILE"
|
||||
echo "Archivos generados:" | tee -a "$REPORT_FILE"
|
||||
echo " - Log detallado: $LOG_FILE" | tee -a "$REPORT_FILE"
|
||||
echo " - Reporte completo: $REPORT_FILE" | tee -a "$REPORT_FILE"
|
||||
}
|
||||
|
||||
main() {
|
||||
echo "========================================="
|
||||
echo " DIAGNÓSTICO DE RED LOCAL - srv-dasu"
|
||||
echo "========================================="
|
||||
echo ""
|
||||
|
||||
# Inicializar archivos
|
||||
> "$LOG_FILE"
|
||||
> "$REPORT_FILE"
|
||||
|
||||
# Verificar dependencias
|
||||
if ! check_dependencies; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Verificar interfaz
|
||||
if ! check_interface; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Ejecutar diagnósticos
|
||||
get_interface_info
|
||||
get_routing_info
|
||||
check_dhcp_info
|
||||
scan_local_network
|
||||
check_tailscale
|
||||
generate_recommendations
|
||||
generate_summary
|
||||
|
||||
echo ""
|
||||
success "Diagnóstico completado exitosamente"
|
||||
echo ""
|
||||
echo "Para configurar IP local en $INTERFACE, edite:"
|
||||
echo " sudo nano /etc/network/interfaces"
|
||||
echo ""
|
||||
echo "Agregue las líneas (adaptando la IP según recomendaciones):"
|
||||
echo " post-up ip addr add 192.168.1.205/24 dev $INTERFACE"
|
||||
echo " pre-down ip addr del 192.168.1.205/24 dev $INTERFACE"
|
||||
echo ""
|
||||
echo "Luego reinicie el servicio de red:"
|
||||
echo " sudo systemctl restart networking"
|
||||
}
|
||||
|
||||
# Ejecutar script principal
|
||||
main "$@"
|
||||
Reference in New Issue
Block a user