On this page
- How does Nagios Core work?
- How do I install it on Ubuntu or Debian?
- How do I install it on Rocky Linux or AlmaLinux?
- How do I open the web interface safely?
- How do I define a host and a service?
- How do I check disks and services on a remote server?
- How do I receive notifications?
- What should I do when something breaks?
- Questions
How does Nagios Core work?
Nagios Core schedules small plugin programs, reads their exit codes (OK, WARNING, CRITICAL, UNKNOWN) and notifies you when a state changes. Everything is plain text: hosts, services, commands, contacts and time periods are object definitions in config files. That makes it predictable, easy to keep in Git and very stable, at the cost of a dated web interface and no built-in graphs. Thousands of plugins exist, and any script that prints one line and exits with the right code can become a check.
If you want time series graphs, pair Nagios with the console Usage graphs or use Prometheus alongside it.
How do I install it on Ubuntu or Debian?
The distribution packages are the simplest path and receive security updates with the rest of the system:
sudo apt update
sudo apt install -y nagios4 monitoring-plugins nagios-nrpe-plugin apache2-utils
apt policy nagios4
sudo nagios4 -v /etc/nagios4/nagios.cfgThe package brings Apache with it and enables the web interface at /nagios4. The last command validates the configuration and should end with Total Errors: 0. Make sure the CGI module is on and the services are running:
sudo a2enmod cgi
sudo systemctl restart apache2
systemctl status nagios4 --no-pagerHow do I install it on Rocky Linux or AlmaLinux?
Nagios Core is packaged in EPEL:
sudo dnf install -y epel-release
sudo dnf install -y nagios nagios-plugins-all nagios-plugins-nrpe httpd php
dnf info nagios | grep -E '^Version'
sudo htpasswd -c /etc/nagios/passwd nagiosadmin
sudo nagios -v /etc/nagios/nagios.cfg
sudo systemctl enable --now httpd nagiosHere the interface lives at /nagios and already asks for the nagiosadmin login you just created. If SELinux blocks a CGI, sudo ausearch -m avc -ts recent shows the denial (see SELinux basics).
How do I open the web interface safely?
The quickest secure option is an SSH tunnel with port 80 closed in the firewall. The Debian and Ubuntu package only accepts requests from local and private addresses by default, and a tunnel makes your browser look local:
ssh -N -L 8080:127.0.0.1:80 deploy@198.51.100.24Then open http://localhost:8080/nagios4 (or /nagios on Rocky and Alma).
To publish it on nagios.example.net instead, add a login and HTTPS. On Ubuntu and Debian, edit /etc/apache2/conf-available/nagios4-cgi.conf and replace each Require ip ... line with:
AuthType Basic
AuthName "Nagios"
AuthUserFile /etc/nagios4/htpasswd.users
Require valid-usersudo htpasswd -c /etc/nagios4/htpasswd.users nagiosadmin
sudo sed -i 's/^use_authentication=0/use_authentication=1/' /etc/nagios4/cgi.cfg
sudo systemctl restart apache2 nagios4Then request a certificate with sudo certbot --apache -d nagios.example.net (see Certbot), allow 80 and 443, and confirm that the page asks for a password before showing anything.
How do I define a host and a service?
Drop your own files into the conf.d folder (/etc/nagios4/conf.d on Ubuntu and Debian, /etc/nagios/conf.d on Rocky and Alma). Here is a web server with a ping check, an HTTPS check and a certificate expiry check:
define command {
command_name check_site_https
command_line $USER1$/check_http -H $ARG1$ -S --sni -e 200
}
define command {
command_name check_site_cert
command_line $USER1$/check_http -H $ARG1$ -S --sni -C 14
}
define host {
use linux-server
host_name web1
address 198.51.100.40
}
define service {
use generic-service
host_name web1
service_description HTTPS
check_command check_site_https!example.net
}
define service {
use generic-service
host_name web1
service_description Certificate
check_command check_site_cert!example.net
}Validate and reload; a failed validation leaves the running config untouched:
sudo nagios4 -v /etc/nagios4/nagios.cfg && sudo systemctl reload nagios4How do I check disks and services on a remote server?
Use check_by_ssh: Nagios logs in with a key and runs a plugin on the remote side. Nothing extra listens on the internet, and the traffic is encrypted, which matters because our servers talk to each other over public IPs. On the Nagios server, create a key for the nagios user:
getent passwd nagios | cut -d: -f6
sudo -u nagios ssh-keygen -t ed25519 -N "" -f "$(getent passwd nagios | cut -d: -f6)/.ssh/id_ed25519"On the remote server, install the plugins, create a matching user and add the public key restricted to the Nagios server address:
sudo apt install -y monitoring-plugins-basic # Rocky/Alma: sudo dnf install -y nagios-plugins-disk
sudo useradd -m -s /bin/bash nagios
sudo -u nagios mkdir -m 700 /home/nagios/.ssh
echo 'from="203.0.113.10" ssh-ed25519 AAAA...key nagios' | sudo -u nagios tee /home/nagios/.ssh/authorized_keysBack on the Nagios server, log in once as the nagios user to accept the host key, then define the check:
define command {
command_name check_remote_disk
command_line $USER1$/check_by_ssh -H $HOSTADDRESS$ -l nagios -C "/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /"
}On a Rocky or Alma target the plugin path is /usr/lib64/nagios/plugins instead. The NRPE daemon is an alternative; if you choose it, allow TCP 5666 only from the Nagios server and keep allowed_hosts in nrpe.cfg to that one address.
How do I receive notifications?
Set your address in the nagiosadmin contact (objects/contacts.cfg). The stock commands pipe mail through the local mail command, so the server needs a mail transfer agent that relays through an authenticated SMTP service on port 587; ask support by ticket before planning direct delivery on port 25. Many people replace the mail command with a short script that posts to a chat webhook, which avoids mail entirely.
What should I do when something breaks?
- 403 Forbidden in the browser: you are not coming through the tunnel or the
Requirelines were not updated. - Check shows (Return code of 127 is out of bounds): the plugin path is wrong; look in
/usr/lib/nagios/pluginsor/usr/lib64/nagios/plugins. - check_by_ssh times out: the host key was never accepted, or the remote firewall blocks SSH from the Nagios address.
- Commands from the web UI fail: external commands need
check_external_commands=1and a writable command file; readjournalctl -u nagios4.
Plans that fit this guide
Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.
Questions about Nagios Core
Is Nagios Core free?
Yes, Nagios Core is open source. This guide installs it from Debian, Ubuntu and EPEL packages.
Why is the package version older than the project site?
Distributions ship tested versions with security fixes backported. Check yours with apt policy nagios4 or dnf info nagios.
Does Nagios draw graphs?
Not by itself. Use the console Usage graphs for the outside view, or add a metrics tool such as Grafana for detailed history.
NRPE or check_by_ssh?
check_by_ssh reuses SSH, so no new port opens. NRPE scales better for many checks; restrict port 5666 to the Nagios server if you use it.
How do I test a plugin by hand?
Run it as the nagios user, for example sudo -u nagios /usr/lib/nagios/plugins/check_http -H example.net -S, then check echo $? for the exit code.
More in Monitoring and logs
- Netdata real-time monitoring
- Uptime Kuma status page
- Prometheus and node_exporter
- Grafana dashboards
- Zabbix monitoring
- Beszel lightweight monitoring
- Loki and Alloy for central logs
- Cacti graphs with SNMP
- Monit for self-healing services
- btop, htop and other live monitors
- Central logs with rsyslog
- Rotate logs with logrotate
- Read logs with journalctl
- Graylog log management
- Observium network monitoring
- Vector log and metrics pipeline