Wednesday, March 21, 2012

Monitor the bandwidth of your D-Link ADSL router from a linux box

Many ISP's provide the D-Link DSL-502T ADSL router with their Tri-Band broadband connection.
This simple howto allows you to monitor the bandwidth of your D-Link ADSL router from a linux box.
The procedure should work for any other router allowing snmp too..
There are lots of cool things you can do with mrtg. visit www.mrtg.org

You can log in to the D-Link DSL-502T ADSL router via web browser. By default its set up at http://192.168.1.1 default username & password are 'admin'.
Click on advance tab at the top, enable the checkboxes of Enable SNMP Agent & Enable SNMP Traps. Ensure community name is public ( you can change it to whatever you like but then just match the same in the following cfgmaker command.), Click apply. Go to tools on top tab, system on left hand tab & click on 'Save & Reboot' to save your setting & restart the router. Thats it for the router.
Now for the linux configuration part.
The following is for a RedHat / Fedora type system. You can adapt easily for any Linux flavor.

$yum -y install httpd mrtg net-snmp-utils # In case you don't have these installed already.
$cfgmaker --noreversedns public@192.168.1.1 --ifdesc=name --ifref=name --output=~/dlinkmrtg.cfg
## match the community name 'public' and / or IP of your router.

Edit the file dlinkmrtg.cfg with your favorite text edit
## You may want to un-comment the growright & bits line.
#Options[_]: growright, bits
## Also you may want to run mrtg in daemon mode at a set frequency.
## If so add following two lines in the global config of dlinkmrtg.cfg ( Without the comment # ofcourse)
#RunAsDaemon:Yes
#Interval:5
## runs mrtg every 5 minutes

$cd /var/www/mrtg
$indexmaker ~/dlinkmrtg.cfg --output=index.html
$env LANG=C /usr/bin/mrtg ~/dlinkmrtg.cfg  #run this command at least 3 times..

Edit /etc/httpd/conf.d/mrtg.conf to allow whoever u want to access the mrtg graphs.
By default it only allows localhost.

$echo 'env LANG=C /usr/bin/mrtg ~/dlinkmrtg.cfg' >> /etc/rc.local
to start mrtg at boot or you can comment the RunAsDaemon:Yes in dlinkmrtg.cfg & run above through cron. Whatever..

Start httpd service on your linux box
$service httpd start

Visit http://<IP of your Linux Box>/mrtg/

Enjoy
Regards
kk

No comments:

Post a Comment