WRT54GL, Tomato firmware and bandwidth monitoring via SNMP

SNMP is quite interesting if you like to control the bandwidth usage of your roomies – or family members. I for one have used it in the past to monitor my sister’s bandwidth usage. After all, this is my internet connection, and noone elses.

Since I’ve switched to the Tomato firmware, however, I haven’t been able to keep track of bandwidth movement other than via the built-in bandwidth meter on the webif. Tomato is quite a bit more lightweight than DD-WRT, which has an SNMP server integrated, and hence, in order to use SNMP with Tomato, you’ll have to add it somehow. This is what I am going to explain here in a couple of steps. I’m going to assume that you already have Tomato installed and configured. This might work for other firmwares that don’t have SNMP integrated already, but I don’t know.

  1. First, you’ll have to create a network share on a box inside your LAN that runs 24/7. Either 24/7, or at least whenever you boot up your WRT device. You can do this on either a Windows box and create a user that has exclusive rights to mount network shares, or you can do this on a Linux box using Samba and creating a smbshare. You could also do this by using the empty space on the flash chip, i however wouldn’t recommend that you do so – since repeatedly writing to that chip will wear its quality down.
  2. Mount the network share. Go to your Tomato configuration, go to Administration, then CIFS Client. Enable one of the shares and enter its details. UNC is the path of the share. This is something like “\\ip-address-of-the-computer-that-contains-the-share\share-name”. As username and password, you will need to input what a noted in 1. – a user that you created solely for the purpose of accessing windows network shares. How you do the latter is a matter that I leave to google to explain to you. The rest of the settings can be left free. Hit Save. Maybe reboot. Can’t be of any harm.
  3. SSH to your router and create a directory on the newly-mounted network share. Call it “sbin”:

    # cd /cifs1
    # mkdir sbin

  4. Download the following file onto your WRT. It’s a static build of an SNMP daemon with all of the libraries built-in, hence its size (732520 bytes). Also check that its md5sum reads as “ae0d622648efdb8dceb7b3b5a63e23ac”:

    # wget http://bok.xs4all.nl/downloads/snmpd.zip
    Connecting to bok.xs4all.nl[]:80
    # unzip snmpd.zip && rm snmpd.zip
    Archive: snmpd.zip
    inflating: snmpd
    # md5sum snmpd
    ae0d622648efdb8dceb7b3b5a63e23ac snmpd

  5. Next, you’ll have to create a configuration file for snmpd. You can do this by just opening an instance of notepad wordpad on your Windows box, copying these contents and saving it in the directory where snmpd resides as snmpd.conf:

    com2sec ro default public
    com2sec rw localhost private

    group public v1 ro
    group public v2c ro
    group public usm ro
    group private v1 rw
    group private v2c rw
    group private usm rw

    view all included .1

    access public “” any noauth exact all none none
    access private “” any noauth exact all all all

    I got this config from the ipkg-package of the DD-WRT distribution.

  6. Now start that thing using the configuration file you just created. I’ve added the -s switch to have it log into the syslog located at /var/log/messages. This flag isn’t mandatory though, if everything works, you can leave it out:

    # /cifs1/sbin/snmpd -s -c /cifs1/sbin/snmpd.conf &

  7. The snmp daemon should be running now. Check the syslog for the following line. if it is not accompanied by any additional lines, you should be good to go:

    # cat /var/log/messages | grep -i snmpd
    Jan 21 20:54:43 daemon.info snmpd[361]: NET-SNMP version 5.0.9

  8. If you want the daemon to run every time the router boots up, go to Administration -> Scripts -> Init, then add these lines:

    # snmp daemon
    sleep 30
    /cifs1/sbin/snmpd -s -c /cifs1/sbin/snmpd.conf &

  9. Now let’s look how we can visualize this. I’m using SNMPTrafficGrapher (STG from now on) for Windows, it’s quite old and apparently development has stopped, but hey, whatever. I haven’t found a more convenient application yet. In order to get the correct OIDs for STG, you have to use SNMPTester to get all available OIDs from your box. Fire up the application, punch in the IP address of your router and use SNMP version V2c. Also select Scan Available Interfaces. Hit 3. Run Test. It’ll spit out a whole bunch of lines, whereof only the last eight or so are important and should look something like this (on a WRT54GL):

    Found interfaces:
    1,lo,,Software Loopback,Connected,10000 kb/s,1 (lo)
    2,eth0,,Ethernet,Connected,10000 kb/s,2 (eth0)
    3,eth1,,Ethernet,Connected,10000 kb/s,3 (eth1)
    4,vlan0,,Ethernet,Connected,10000 kb/s,4 (vlan0)
    5,vlan1,,Ethernet,Connected,10000 kb/s,5 (vlan1)
    6,br0,,Ethernet,Connected,10000 kb/s,6 (br0)
    7,ppp0,,PPP,Not Connected,0 kb/s,7 (ppp0)

  10. Back to STG: hit F9 for its settings. Set the router ip as Target Address, Community to “public” and the following values to “Green” OID and “Blue” OID1:

    with x being the number before the interface listed with “br0” in the list we just got. In my case, it was 6. Also set your Update Period to 1000ms, which translates to 1s update intervals. Take a look at the rest of the settings and adapt them to your likings, then hit OK and go to File -> Save to save that configuration somewhere. From now on, you should always start STG with the configuration file you have just saved. Cause some traffic. STG should now show a blue line displaying your downstream- and a green one showing your upstream-traffic.

Alright, all done. I hope this helps some people.


initial howto from bokh and my way of solving my issue

http://cacti.net/ & http://oss.oetiker.ch/mrtg/
two linux solutions to SNMP monitoring

7 responses to “WRT54GL, Tomato firmware and bandwidth monitoring via SNMP

  1. okay, so turns out that saving the configuration file with notepad might not be the best of ideas after all. take a look at page two of the forums thread of the first link.

    instead of using notepad, you could try wordpad and save as plain text, as wordpad saves linebreaks (\n) differently as notepad.

    alternatively, you can always telnet/ssh to your device and create the configuration file by pasting its contents into an echo-command and saving the output to the snmpd.conf, like so:

    # echo “com2sec ro default public
    > com2sec rw localhost privategroup public v1 ro
    > group public v2c ro
    > group public usm ro
    > group private v1 rw
    > group private v2c rw
    > group private usm rw
    > view all included .1
    > access public \”\” any noauth exact all none none
    > access private \”\” any noauth exact all all all
    ” > /cifs1/sbin/snmpd.conf

    note that everything in italic is a paste, excluding the > symbols which echo puts in front of every line so long as the quotation mark is not closed.
    also note that you will have to escape (put a backslash in front of) the quotation marks in both access-lines, as these won’t be shown in the configuration file otherwise.

    thanks to Hypernova for bringing this to my attention.

  2. Just came accross this, I’m wondering in which scenarios is SNMP more useful then the already built-in bandwidth meter in the web interface. I’d very much appreciate it if you could list a few.

    • well, there are for instance the many applications that let you display snmp data (not necessarily bandwidth information…) als graphs or otherwise. lots of sidebars offer that functionality, same goes for samurize. also, in order to observe live bandwidth allocation, you’d have to keep your browser running all the time. STG, which i mentioned in the article, lets you do that without having a browser open, at relatively low resource loss. or mrtg. take your pick.

  3. Thank you very much
    I have been following the file properly and I have tried to tinker with my WRT54 Router for a number of helps and failed, I have atleas managed to go far with this file,
    Actually I had to use both ma machine (Ubuntu) and a windows machine to be able to get to that level.
    Any way am getting a problem when I get to Run Paessler SNMP Tester 3.2 from http://www.paessler.com/download/freeware/snmptester I am told that there is no standard interface found. yet according to you there are supposed to be some different responses.
    I hope you find a reply and help from your page.
    Thank you

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s