Master Your Network: How to Set Up Nagios from Scratch

Learn how to build a powerful network monitoring system from the ground up using Nagios Core.

Nagios

Why Monitor Your Network?

Linux

What is Nagios?

Nagios is a popular, free, and open-source tool used to monitor computers, networks, and services. It acts like a digital watchman for your IT system. By constantly checking your servers, routers, and applications, it ensures everything is running smoothly and alerts you the moment something goes wrong.

The system works in two main parts: the core engine and the plugins. The core engine is the brain that schedules checks, manages data, and sends out alerts. The plugins are small worker programs that do the actual checking, like testing if a website is loading, checking how much hard drive space is left, or seeing if a server is online.

Using Nagios helps you find and fix problems before your users even notice them. Instead of waiting for a customer to complain that a system is broken, Nagios will send you an email or alert instantly. This saves time, reduces downtime, and keeps your entire network healthy and reliable.

Prerequisites

  • A server running Ubuntu Linux (20.04, 22.04, or 24.04).
  • A user account with sudo (administrator) privileges.
  • A basic understanding of using the Linux command line.
  • An active internet connection to download the required software packages.

Step-by-Step Installation

1

Install Build Dependencies

Includes necessary dependencies for plugin compilation
This installs the C compiler, Apache/PHP, and the underlying network tools (like SNMP and DNS utils) so your plugins can fully compile.
BASH
sudo apt update
sudo apt install -y autoconf gcc libc6 make wget unzip apache2 php libapache2-mod-php libgd-dev libssl-dev build-essential dnsutils snmp snmpd smbclient
2

Download the Latest Nagios Core Source

Extracts the single .tar.gz asset
Using the GitHub API to fetch the most recent official release tarball. The head -n 1 ensures we only grab the primary source file if multiple assets exist.
BASH
cd /tmp
wget --output-document="nagioscore.tar.gz" $(wget -q -O - https://api.github.com/repos/NagiosEnterprises/nagioscore/releases/latest | grep '"browser_download_url":' | grep -o 'https://[^"]*\.tar\.gz' | head -n 1)
tar xzf nagioscore.tar.gz
cd /tmp/nagios-*
3

Compile Nagios and Create System Users

Running as an unprivileged user
This configures the build for Apache. Notice we are running the configuration and compilation steps without sudo, which is a security best practice.
BASH
./configure --with-httpd-conf=/etc/apache2/sites-enabled
make all
sudo make install-groups-users
sudo usermod -a -G nagios www-data
4

Install Binaries and Configuration Files

Run the following commands sequentially to install the daemon, configuration files, and the Apache web server configuration.
BASH
sudo make install
sudo make install-daemoninit
sudo make install-commandmode
sudo make install-config
sudo make install-webconf
5

Create the Administrative Web Account

Nagios requires Apache's authentication to access the dashboard. Enable the required modules and create the nagiosadmin user.
BASH
sudo a2enmod rewrite cgi
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
sudo systemctl restart apache2
Note: You will be prompted to type a password. Remember this password; you will need it to log in to the web dashboard.
6

Download and Install Nagios Plugins

Provides the actual monitoring functionality
Nagios Core is just the engine; the plugins actually perform the checks. Again, compiling is done without root privileges.
BASH
cd /tmp
wget --output-document="nagios-plugins.tar.gz" $(wget -q -O - https://api.github.com/repos/nagios-plugins/nagios-plugins/releases/latest | grep '"browser_download_url":' | grep -o 'https://[^"]*\.tar\.gz' | head -n 1)
tar xzf nagios-plugins.tar.gz
cd /tmp/nagios-plugins-*

./configure
make
sudo make install
7

Configure Firewall and Start the Service

Finally, allow HTTP traffic through the firewall and start the Nagios service.
BASH
sudo ufw allow Apache
sudo systemctl enable nagios
sudo systemctl start nagios
Once complete, open your web browser and navigate to http://<your-server-ip>/nagios . Log in using nagiosadmin and the password you set in Step 5.

Discover CTCservers Dedicated Server Locations

CTCservers servers are available around the world, providing diverse options for hosting websites. Each region offers unique advantages, making it easier to choose a location that best suits your specific hosting needs.