How To Install / Configure MRTG On CentOS 5

The Multi Router Traffic Grapher (MRTG) is a tool to monitor the traffic load on network links. MRTG generates HTML pages containing PNG images which provide a LIVE visual representation of this traffic. MRTG is written in Perl and comes with full source code.

In this article, we will go through the installation of MRTG on a centos system to monitor the network traffic on a router. Here, the server ‘’ is the web server running CentOS5 where we need to install MRTG for traffic monitoring and ‘’ is the router for which network traffic need to be monitored.

Step 1: Install MRTG on web server ‘’

CentOS provides MRTG package which can be installed using yum.

yum install mrtg

Step 2: Configuring MRTG

Next, we need to configure mrtg for monitoring a network device. This is done by creating a mrtg.cfg file which defines what you want to monitor. MRTG provides a binary ‘cfgmaker’ to automatically create the configuration file ‘mrtg.cfg’.

/usr/bin/cfgmaker --global 'WorkDir: /var/www/html/mymrtg' [email protected] --output /etc/mrtg/mrtg.cfg

This command will create the mrtg configuration file ‘/etc/mrtg/mrtg.cfg’ and will set the ‘workdir’ (which is /var/www/html/mymrtg here) to store the MRTG graphs. The directory ‘/var/www/html’ is the default document root for this web server. ‘vsnl’ is the read only community name of the device you want to create a configuration for. If you are using the wrong community name you will get no response from the device. ‘’ is the IP address of the SNMP-manageable device (This configuration should be done in the router which we will discuss later).

Step 3 : Run MRTG

After creating the configuration file, you can run MRTG to create MRTG graphs for the first time.

/usr/bin/mrtg /etc/mrtg/mrtg.cfg

This will query the router and also create the first mrtg traffic graphs and web pages. When you run mrtg for the first time, there will be a lot of complaints about missing log files, which you can safely ignore.

Step 4 : Create the index file for mrtg to access it through browser

Run the ‘indexmaker’ command to create the index file.

/usr/bin/indexmaker --output index.html /etc/mrtg/mrtg.cfg

Step 5: Add cron job to periodically run mrtg

Edit the crontab using ‘crontab –e’ and add the following cron job.

*/5 * * * * usr/bin/mrtg /etc/mrtg/mrtg.cfg --logging /var/log/mrtg.log

Router Side Configuration

Step 1: Verify snmp is installed and running

CentOS provides snmp package for installation which can be installed using yum.

yum install net-snmp net-snmp-utils

Step 2: Configure snmpd

In order for the MRTG to poll information from a Router (or a server), we need to setup read-only (public) community on the router. For this, you need to edit the configuration file ‘/etc/snmp/snmpd.conf’ with the following contents.

rocommunity vsnl
interface eth0

Now, restart snmpd.

chkconfig snmpd on
service snmpd restart

The configuration part is completed. Now, you will be able to view the network traffic using the link

A sample graph can be seen as follows.

MRTG Graph

Leena 12:54 pm

About Leena

Leena has been working on Linux operating systems and open source technologies for past 6 years. She loves to read and write on Linux related technologies and is a big fan of open source software’s.

Author Archive Page

Have anything to say?

Your email address will not be published. Required fields are marked *

All comments are subject to moderation.