Sharing a .cfg between two routers

Discussion in 'Tomato Firmware' started by fyellin, Mar 25, 2009.

  1. fyellin

    fyellin LI Guru Member

    As I mentioned in this thread, I took two identically configured (exept for name and LAN) WRT54GL routers and compared their nvram variables, and discovered that they differered in only 13 variables. In addition, examination of the tomato source code indicates that if et0macaddr is removed, a tomato router will happily read the configuration file written by another machine, as long as they are the same hardware.

    At SgtPepperKSU's suggestion, I have written the following script:
    #!/usr/bin/env python
    import gzip
    import sys
    delete_list = [
                   # MAC Addresses
                   "et0macaddr",            # MUST DELETE hardware address of the LAN, assigned by manufacture
                   "wan_hwaddr",            # Advanced > MAC Address > WAN Port
                   "wl0_hwaddr",            # Advanced > MAC Address > Wireless Interface
                   "lan_hwaddr",            # current address of the LAN, either et0macaddr or assigned by user
                   "lan_ipaddr",            # Basic > Network > Router IP Address
                   "router_name",           # Basic > Identification > Router Name
                   "wan_hostname",          # Basic > Identification > Hostname
                   "sshd_hostkey",          # Private key generated by sshd
                   "http_id",               # Private key generated by httpd
                   # Unknown
                   "eou_device_id",         # meaning unknown
                   "eou_private_key",       # meaning unknown
                   "eou_public_key",        # meaning unknown
                   "sdram_ncdl",            # meaning unknown
    delete_map = dict([(item, None) for item in delete_list])
    def keepItem(nameEqualsValue) :
        # The format seems to have extra nulls at the end.  Keep them
        if nameEqualsValue == "" :
            return True
        # Everything else must be name=value
        if '=' not in nameEqualsValue :
            raise ValueError
        [name, value] = nameEqualsValue.split('=', 1)
        return name not in delete_map
    def purge(oldFileName, newFileName) :
        # Read the header and the rest of the file
        zfile = gzip.GzipFile(oldFileName);
        header =;
        contents =;
        # Get the pairs, throw away the bad ones
        pairs = contents.split('\0')
        pairs = filter(keepItem, pairs)
        contents = '\0'.join(pairs)
        # Write the result right back out
        zfile = gzip.GzipFile(newFileName, 'wb')
    if len(sys.argv) == 3 :
        purge(sys.argv[1], sys.argv[2])
    else :
        print sys.argv[0], "input output"
    Presuming that you already have Python, write this script to a file, make it executable and then run
    ./ existingConfigFileName newConfigFileName
    (Could someone else provide Windows instructions?) The old configuration file will be copied to the new configuration file with the specified nvram variables deleted.


    I have verified that the new configuration file looks like a legitimate configuration file.

    I have not actually tried loading the new configuration file into a router, clean or otherwise. (I don't own a spare router, and I don't want to risk bricking one of mine).

    I have determined the values of the changed NVRAM variables by looking at a WRT54GL. I do not know whether you need different variables on other pieces of hardware.

    If your goal is to clone a broken machine's configuration, rather than to copy one machine's configuration onto another, you might consider removing some of the variables from the delete_list. et0macaddr is the only one that absolutely must be deleted to keep Tomato happy.

    You are using this code at your own risk. I offer this code merely as sample code of how one can read, modify, and write a configuration file.

  2. Toastman

    Toastman Super Moderator Staff Member Member

    I am going to try deleting et0macaddr, rezip, and upload, which would be sufficient for my needs. I'll post back..

    Hmmm. bother. The rezipped file did not decompress. I have done something wrong.

    I did something similar a few months ago, I saved the file, unzipped and edited (added my MAC lists) and then rezipped and restored, it did work, so I was keen to try this out. I'll go scratch my head a bit...
  3. fyellin

    fyellin LI Guru Member

    Let me know if there's anything I can do to help.

    The code is pretty clear, I hope.
  4. Toastman

    Toastman Super Moderator Staff Member Member

    It is just me, probably doing something wrong. I am not using the scripts - just unzip/zip again, but in Windows. The gzip utility I downloaded *seems* to be broken. I need a windows version of gzip I think! Is there one? I will look for a replacement.

    EDIT: utility downloaded from different site, and works now. I will repeat my experiment.

    EDIT: OK, the experiment did not work as expected. I used GNUWIN32 to unzip a backup file, carefully deleted only the et0macaddr entry, and repacked. I then uploaded to a different AP, which accepted the file, but it did not come back up after rebooting. I had to reset the AP to defaults and re configure. I have abandoned the experiment for today, as it's getting busy here. The fact that the file was accepted is encouraging, though. If you want to try it yourself, it does look like you would not brick the router.

    Any suggestions?
  5. fyellin

    fyellin LI Guru Member

    Try deleting the "meaning unknown" variables, too. Otherwise, we might have to call this a failed experiment.:confused:
  6. Toastman

    Toastman Super Moderator Staff Member Member

    I'll have a bash at it when things get quiet if I can stay awake!
  7. Toastman

    Toastman Super Moderator Staff Member Member

    I uploaded the .cfg file you sent, this time it bricked the router, power light flashing, all lights on, does not respond in any way. Shorting flash chip pins 15/16 doesn't work either.

    I guess this is a failed experiment!
  8. fyellin

    fyellin LI Guru Member

    Ouch. Sorry.

    I was expecting at worst a router that needed a hard reset. I couldn't imagine it bricking. Okay, I guess that means there's a reason that JonZ only allows the .cfg to be read by the exact same machine that wrote it.

  9. Toastman

    Toastman Super Moderator Staff Member Member

    But - I do seem to remember that one experiment I did last year worked. That was to unzip a cfg, edit it by adding my static DHCP list, and then re-zip and upload. It's such a long time ago I am a little hazy about the details, but iIm pretty sure it worked. For the moment, however, I'll let it be...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice