Setting up MRTG in Debian

    Hello folks. After some setback, I have managed to setup MRTG in my Debian etch box. I thought of posting the process step by step so that it might be useful to someone someday. MRTG, The Multi Router Traffic Grapher, is used to see what a router does. It displays in the form of clean and pretty graphs showing how much traffic flowed through each interface.

Those using debian etch can save a good deal of download time as all the necessary packages are shipped along with it. But still, for those who want the latest of all the packages, can download them from the respective sites as listed below.

The required packages for running MRTG are mrtg itself and snmp (and ofcourse apache2, properly configured and userdir enabled if necessary. It can be enabled by the command a2enmod userdir). In Debian, users can install them by the following command

#apt-get install snmp snmpd mrtg

These get installed in the default locations. Then, first we need to configure snmpd. For this, check if snmpd is running. This can be done as follows.

#ps -e | grep snmpd

If it is running, it gives an output showing the process id and the name(snmpd) of it.

Then we need to run the command snmpwalk. snmpwalk is an SNMP application that uses SNMP GETNEXT requests to query a network entity for a tree of information. The exact command is:

#snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex

To put it simply, the above command queries the SNMP server for the IP addresses of the various interfaces. It will return something like this

IP-MIB::ipAdEntIfIndex. = INTEGER: 1
IP-MIB::ipAdEntIfIndex. = INTEGER: 2

These are my settings and it will vary for you based on your system’s interface configurations. This can be cross-checked by using /sbin/ifconfig -a. If you don’t get the output like something similar to the above seen one, we need to edit the /etc/snmp/snmpd.conf file and configure the snmp server. Open the file /etc/snmp/smpd.conf with your favorite editor. Then do the following.

Find the line

com2sec <some text> default public/private.

Change it to the following lines.

com2sec local localhost public
com2sec mynetwork public

The actual values are based on your network settings. These are the values in my snmpd.conf file. Then in the next few lines below, you will find the following.

group MyROSystem v1 <some text>
group MyROSystem v2c <some text>
group MyROSystem usm <some text>

Replace them with the values that we created above namely, local and mynetwork. So it will look like this:

group MyRWGroup v1 local
group MyRWGroup v2c local
group MyRWGroup usm local
group MyROGroup v1 mynetwork
group MyROGroup v2c mynetwork
group MyROGroup usm mynetwork

Likewise, you will find line like:

view system included

Replace it with the following:

view all included .1 80

Infact, most of these will be available in the file by default, you need to comment out the lines other than what are required. In all the places where it has been mentioned to replace on line with another, it is suficient if the unnecessary line is commented out (using # ).

Next, we need to comment ou the following line:

access MyROSystem “” any noauth exact system none none

And ensure that these lines are present:

access MyROGroup “” any noauth exact all none none
access MyRWGroup “” any noauth exact all all none

Finally, find these lines:

syslocation Unknown (edit /etc/snmp/snmpd.conf)
syscontact Root (configure /etc/snmp/snmp.local.conf)

And replace them with appropriate values. syslocation will be followed by the OS youare running and syscontact will be followed by the system administrator and his mail id. It will be like:

syscontact name <mail-id>

Now restart the snmpd if it is already running or start it if it isn’t. It can be done by:

#/etc/init.d/snmpd restart

Then, run the snmpwalk command show above again:

#snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex

Now, we need to configure MRTG. It is a really simple task. The commands are as follows.

#mkdir /var/www/mrtg

#cfgmaker –global ‘WorkDir: /var/www/mrtg’ –output /etc/mrtg/mrtg.cfg public@localhost

# indexmaker –output=/var/www/mrtg/index.html /etc/mrtg/mymrtg.cfg

The cfgmaker command creates the configurations scripts for MRTG and the indexmaker creates the default index page for the MRTG page. Now to run mrtg,

#mrtg /etc/mrtg/mrtg.cfg

And thats it!!! For the first couple of times it might through out some error messages. Start your favourite browser and view the results

5 thoughts on “Setting up MRTG in Debian”

  1. Why are you called u itself as Unknown Indian – Balchandran I appreciate all the articles and certain of the articles have solved my plenty of all the problems through ur URL

    With Regards and keep it up

    Chandigarh India

    1. @Sidhartha,

      Thanks and glad to know that this blog helped you solve some problems. As to why I am calling myself an Unknown Indian, India is a great land with more than a billion people, and I am just one in a billion and so still unknown. Also, partly because of the book “The Autobiography od an Unknown Indian” by Nirad Choudhuri. And Thanks for your comments. Will definitely post more useful information

  2. Hi. Thanks for your tips. I just completed the configuration of MRTG this morning and it is now working. i can see now the graphs of the router. I followed some of your tips here.


Leave a Reply

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

Unable to load the Are You a Human PlayThru™. Please contact the site owner to report the problem.