main
alexandrev-tibco 2025-05-07 13:22:13 +02:00
commit 8bd19bd826
No known key found for this signature in database
GPG Key ID: 205DAC70EF7BDFD9
8 changed files with 118 additions and 0 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

21
apply.sh Normal file
View File

@ -0,0 +1,21 @@
#!/bin/bash
INTERFACES=("vmbr0" "vmbr1" "eno1" "enp1s0")
echo "==> Aplicando arp_filter..."
for iface in "${INTERFACES[@]}"; do
if [ -f "/proc/sys/net/ipv4/conf/$iface/arp_filter" ]; then
echo 1 > "/proc/sys/net/ipv4/conf/$iface/arp_filter"
fi
done
echo 1 > /proc/sys/net/ipv4/conf/all/arp_filter
echo 1 > /proc/sys/net/ipv4/conf/default/arp_filter
SYSCTL_FILE="/etc/sysctl.conf"
for iface in "${INTERFACES[@]}" all default; do
grep -q "net.ipv4.conf.$iface.arp_filter" "$SYSCTL_FILE" || echo "net.ipv4.conf.$iface.arp_filter = 1" >> "$SYSCTL_FILE"
done
sysctl -p
echo "==> Configuración de arp_filter aplicada correctamente."

21
check-arp-integrity.sh Normal file
View File

@ -0,0 +1,21 @@
#!/bin/bash
IP_LOCAL="192.168.1.100"
MAC_ESPERADA="e8:6a:64:8e:7e:2a"
INTERFAZ_SALIDA="vmbr0"
LOG_FILE="/var/log/arp-monitor.log"
REPO_FIX_SCRIPT="$(dirname "$0")/apply.sh"
RESPUESTA=$(arping -c 3 -I "$INTERFAZ_SALIDA" "$IP_LOCAL" 2>/dev/null | grep reply | head -n1)
MAC_RESPUESTA=$(echo "$RESPUESTA" | awk -F" " '{print $5}' | tr '[:upper:]' '[:lower:]')
FECHA=$(date '+%Y-%m-%d %H:%M:%S')
if [[ -z "$MAC_RESPUESTA" ]]; then
echo "$FECHA - ERROR: No se recibió respuesta ARP de $IP_LOCAL" >> "$LOG_FILE"
elif [[ "$MAC_RESPUESTA" != "$MAC_ESPERADA" ]]; then
echo "$FECHA - ALERTA: MAC inesperada para $IP_LOCAL. Esperada: $MAC_ESPERADA, Recibida: $MAC_RESPUESTA" >> "$LOG_FILE"
echo "$FECHA - Reaplicando configuración arp_filter" >> "$LOG_FILE"
bash "$REPO_FIX_SCRIPT" >> "$LOG_FILE" 2>&1
else
echo "$FECHA - OK: ARP verificado correctamente para $IP_LOCAL (MAC $MAC_RESPUESTA)" >> "$LOG_FILE"
fi

44
setup.sh Normal file
View File

@ -0,0 +1,44 @@
#!/bin/bash
REPO_URL="http://gitea:3000/baphemot/proxmox-node-config.git"
CLONE_DIR="/opt/proxmox-node-config"
MARKER_FILE="$CLONE_DIR/.apply-done"
if [ ! -d "$CLONE_DIR/.git" ]; then
echo "==> Clonando repo desde $REPO_URL..."
git clone "$REPO_URL" "$CLONE_DIR"
else
echo "==> Actualizando repo..."
git -C "$CLONE_DIR" pull
fi
cd "$CLONE_DIR" || exit 1
if [ ! -f "$MARKER_FILE" ]; then
echo "==> Ejecutando apply.sh por primera vez..."
bash "$CLONE_DIR/apply.sh"
touch "$MARKER_FILE"
else
echo "==> apply.sh ya fue ejecutado previamente, se omite."
fi
install_unit() {
local service_name=$1
local timer_name=$2
if ! systemctl list-timers | grep -q "$timer_name"; then
echo "==> Instalando $timer_name..."
cp "$CLONE_DIR/systemd/$service_name" /etc/systemd/system/
cp "$CLONE_DIR/systemd/$timer_name" /etc/systemd/system/
systemctl daemon-reexec
systemctl daemon-reload
systemctl enable --now "$timer_name"
else
echo "==> $timer_name ya está instalado."
fi
}
install_unit apply.service apply.timer
install_unit arp-monitor.service arp-monitor.timer
echo "==> Instalación y configuración completa."

6
systemd/apply.service Normal file
View File

@ -0,0 +1,6 @@
[Unit]
Description=Apply ARP Filter Fix to Network Interfaces
[Service]
Type=oneshot
ExecStart=/opt/proxmox-node-config/apply.sh

10
systemd/apply.timer Normal file
View File

@ -0,0 +1,10 @@
[Unit]
Description=Run apply.sh every 15 minutes
[Timer]
OnBootSec=5min
OnUnitActiveSec=15min
Persistent=true
[Install]
WantedBy=timers.target

View File

@ -0,0 +1,6 @@
[Unit]
Description=Check ARP Table Integrity
[Service]
Type=oneshot
ExecStart=/opt/proxmox-node-config/check-arp-integrity.sh

10
systemd/arp-monitor.timer Normal file
View File

@ -0,0 +1,10 @@
[Unit]
Description=Run ARP monitor every 10 minutes
[Timer]
OnBootSec=3min
OnUnitActiveSec=10min
Persistent=true
[Install]
WantedBy=timers.target