* Conoscenza del computer >> Software >  >> LinkedIn

Come configurare IP statico su server Nagios (Linux) via ifconfig / ip / netplan / NetworkManager

Perché IP statico su Nagios

Un server di monitoraggio Nagios Core / XI deve avere IP **immutabile** per:

  • Agenti NRPE / NSClient++ / check_by_ssh configurati con IP fisso.
  • Firewall regole source/dest IP.
  • DNS record A/PTR stabili.
  • Accesso web UI (es. nagios.azienda.local).
  • Alta disponibilità (VRRP/keepalived) con VIP.

Metodi per distribuzioni moderne (systemd, netplan, NetworkManager)

Metodo 1: netplan (Ubuntu 18.04+, Debian 10+, derivati)

File: /etc/netplan/01-nagios-static.yaml (nome qualsiasi .yaml)

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:  # o ens192, enp3s0 - verificate con `ip link`
      dhcp4: false
      addresses:
        - 192.168.1.100/24   # IP statico + CIDR
      routes:
        - to: default
          via: 192.168.1.1   # Gateway
      nameservers:
        addresses: [192.168.1.1, 8.8.8.8, 1.1.1.1]  # DNS

Applicate:

sudo netplan generate
sudo netplan apply
# Verificate: ip addr show eth0

Metodo 2: NetworkManager (RHEL/CentOS/Alma/Rocky 8+, Fedora, Ubuntu Desktop)

nmcli (CLI, scriptabile):

sudo nmcli con add type ethernet con-name "Nagios-LAN" ifname eth0 ipv4.method manual ipv4.addresses 192.168.1.100/24 ipv4.gateway 192.168.1.1 ipv4.dns "192.168.1.1 8.8.8.8"
sudo nmcli con up "Nagios-LAN"
# Verificate: nmcli device show eth0

nmtui (TUI): sudo nmtui → Edit a connection → Manual → inserite IP/GW/DNS → OK → Activate.

Metodo 3: /etc/network/interfaces (Debian/Ubuntu legacy, senza netplan/NetworkManager)

auto eth0
iface eth0 inet static
    address 192.168.1.100
    netmask 255.255.255.0
    gateway 192.168.1.1
    dns-nameservers 192.168.1.1 8.8.8.8

Riavviate networking: sudo systemctl restart networking o sudo ifdown eth0 && sudo ifup eth0.

Metodo 4: ip comando (temporaneo, non persiste al reboot)

sudo ip addr add 192.168.1.100/24 dev eth0
sudo ip route add default via 192.168.1.1
# Per DNS: editate /etc/resolv.conf (se non gestito da systemd-resolved/NetworkManager)

Multi-homing (più interfacce)

Ripetete per eth1, eth2... con IP/subnet diversi. Attenzione: un solo default gateway** globale. Usate `metric` o `routing tables` / `policy routing` se servono gateway multipli.

Verifica post-configurazione

ip addr show
ip route show
cat /etc/resolv.conf
ping -c 3 8.8.8.8
ping -c 3 google.com
# Test Nagios: curl https://localhost/nagios  (o IP statico)

Best practice Nagios

  • Riservate IP nel DHCP server (MAC binding) anche se statico su host (doppia sicurezza).
  • Configurate hostname FQDN in /etc/hostname e /etc/hosts (127.0.1.1 nagios.azienda.local nagios).
  • Time sync: chrony o ntp verso NTP aziendali/pool.ntp.org.
  • Firewall host (ufw/firewalld/iptables): allow 5666/TCP (NRPE), 80/443 (web UI), 22 (SSH mgmt), ICMP.
  • Backup configurazione /etc/netplan/ o /etc/NetworkManager/system-connections/.

Nota su articolo originale

L'articolo usava sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0. ifconfig è deprecato** (net-tools), non persiste al reboot, e non gestisce gateway/DNS. Usate metodi sopra per configurazione persistente e completa.

LinkedIn

  • --热点software