How to Install and Configure MRTG on Ubuntu 18.04

MRTG also known as "Multi Router Traffic Grapher" is a free and open source tool to monitor the traffic load on network links. You can monitor daily, weekly, monthly and yearly network traffic using MRTG. MRTG supports for Windows and Linux operating system. MRTG provides a simple web interface to display network traffic data in graphical form.

In this tutorial, we will learn how to install MRTG on Ubuntu 18.04 server.


  • A server running Ubuntu 18.04.
  • A non-root user with sudo privileges.

Install Required Packages

Before starting, you will need to install some packages to your system. You can install all of them by running the following command:

sudo apt-get install apache2 snmp snmpd -y

Once all the packages are installed, start apache and snmp service and enable them to start on boot with the following command:

sudo systemctl start apache2
sudo systemctl enable apache2
sudo systemctl start snmpd
sudo systemctl enable snmpd

Install and Configure MRTG

By default, MRTG is available in the Ubuntu 18.04 default repository. You can install it by just running the following command:

sudo apt-get install mrtg -y

After installing MRTG, you will need to configure it to monitoring target devices. First, create a MRTG directory inside Apache root directory:

sudo mkdir /var/www/mrtg

Next, give proper ownership to the mrtg directory:

sudo chown -R www-data:www-data /var/www/mrtg

Next, rebuild MRTG configuration with the following command:

sudo cfgmaker [email protected] > /etc/mrtg.cfg

You should see the following output:

cfgmaker [email protected] > /etc/mrtg.cfg
--base: Get Device Info on [email protected]:
--base: Vendor Id: Unknown Vendor -
--base: Populating confcache
--base: Get Interface Info
--base: Walking ifIndex
--base: Walking ifType
--base: Walking ifAdminStatus
--base: Walking ifOperStatus
--base: Walking ifMtu
--base: Walking ifSpeed

Next, Create an index file for the /web server with the following command:

sudo indexmaker /etc/mrtg.cfg > /var/www/mrtg/index.html

Configure Apache for MRTG

Next, you will need to create an apache virtual host file for MRTG. You can do this with the following command:

sudo nano /etc/apache2/sites-available/mrtg.conf

Add the following lines:

<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/var/www/mrtg"
<Directory "/var/www/mrtg/">
Options None
AllowOverride None
Order allow,deny
Allow from all
Require all granted
TransferLog /var/log/apache2/mrtg_access.log
ErrorLog /var/log/apache2/mrtg_error.log

Save and Close the file, when you are finished. Then enable virtual host and restart apache service to apply all the changes:

sudo a2ensite mrtg
sudo systemctl restart apache2

Now, open your web browser and type the URL You will be redirected to the following page:

Share this page:

Suggested articles

5 Comment(s)

Add comment


By: Kip

I get to the line:

sudo cfgmaker [email protected] > /etc/mrtg.cfg

bash: /etc/mrtg.cfg: Permission denied

I do not have a user public on my machine. Should I?Does it need to be set up in a particular way?


By: Rex

the public is for your SNMP daemon. You will need to ensure snmpd is installed and running. You will also have to put an entry into cron so that mrtg can update the entries.

By: Douglas

I get to 

sudo indexmaker /etc/mrtg.cfg > /var/www/mrtg/index.html

and get error message:

ERROR: did not find any matching data in cfg file

also make some changes on the 

mrtg.conf files by replacing to mydomain.local and port 80 to 82

and get err_connection_reffused message

Also try with port *:80 with Apache2 Ubuntu Default Page reply.

By: Brian

Everything works up until you need to make the index file. At that point, when I use that command "sudo indexmaker /etc/mrtg.cfg > /var/www/mrtg/index.html" I get an error back that says ERROR: did not find any matching data in cfg file.

It will not let me make the index page. What am I missing here?

By: Brian

I found the error in your documentation. Before you run the indexmaker, you need to first edit the snmpd.conf file and uncomment the line that says "#rocommunity public localhost" so it looks like "rocommunity public localhost"