Discussion in 'Tomato Firmware' started by B.S., May 20, 2012.

  1. B.S.

    B.S. Serious Server Member

    Who says that 192.168.x.y has to be x=1 for the subnet (and netmask= you (and everyone else) uses? Nobody, but it turns out to be more painful than it should be if you pick something else. I chose something else for my gateway/router's LAN, and wanted its dhcp server to, you know, dynamically assign all of the addresses I would need. That seems to work fine with phones, tablets, and PCs, but another wireless access point/switch? Egads.

    I wanted to use my backup router (another Linksys E3000) as a wireless access point/switch to extend wireless coverage in my house (and additional wired ports) by connecting it to the wired LAN coming in on the opposite side of the house. Tomato (Tomato Firmware v1.28.7498 MIPSR2-Toastman-VLAN-RT K26 USB VPN) has a nice GUI for entering a host name (how I prefer to address devices by name rather than by IP), disabling the built-in DHCP server, and even assigning the WAN port to switch (making for another wired LAN port). What it doesn't have in the GUI is a way to set it to use the built-in DHCP client to request an IP from another DHCP server on the LAN.

    I searched the web a lot to see that there seem to be potential ways to do it in OpenWRT and in DD-WRT, but I didn't find anything that I was sure would work with Tomato. If I wasn't so determined, I would have just assigned it a static address and been done with it, but after too much time researching, I present a way to do it. All you have to do is:

    0. Set a password and disable all of the things you don't want for a WAP/switch (I like to leave ssh on).
    1. Set a host name to easily find the access point for web admin (e.g. http(s)://accesspoint).
    2. Disable the DHCP server and preferably set the WAN port to switch. Advanced routing to router.
    3. Enable jffs and create the /jffs/etc/config directory.
    4. Put the following script named "50-udhcpc.fire" into the created /jffs/etc/config/ directory.
    5. Make the script executable, and reboot.

    Its IP address will be the default ( when initially directly connected to your computer, and when later connected to your LAN, will get its IP address from your LAN's DHCP server. If it gets an address from a DHCP server, it will keep that until the lease expires or it is rebooted/turned off and on, etc. It will also renew and adapt to different IP addresses assigned through DHCP on expiration.

    It is hard to make a Tomato router function at this low a level but it can be done.

    #  50-udhcpc.fire
    #+ both runs udhcpc on firewall up and hosts its event script from /jffs/etc/config/
    if [ "${1}" ]; then
        [ "${1}" != "leasefail" ] && [ "${1}" != "renew" ] && [ "${1}" != "bound" ] && valid=false
        if ${valid} ; then
            oldipadd="$(nvram get lan_ipaddr)"
            oldnmask="$(nvram get lan_netmask)"
            oldgatew="$(nvram get lan_gateway)"
            oldwdns="$(nvram get wan_dns)"
            if [ "${1}" != "leasefail" ] ; then
            [ "${oldipadd}" = "${newipadd}" ] && [ "${oldnmask}" = "${newnmask}" ] && [ "${oldgatew}" = "${newgatew}" ] && [ "${oldwdns}" = "${newwdns}" ] && changed=false
            if ${changed} ; then
                [ "${oldipadd}" != "${newipadd}" ] && "$(nvram set lan_ipaddr=${newipadd})"
                [ "${oldnmask}" != "${newnmask}" ] && "$(nvram set lan_netmask=${newnmask})"
                [ "${oldgatew}" != "${newgatew}" ] && "$(nvram set lan_gateway=${newgatew})"
                [ "${oldwdns}" != "${newwdns}" ] && "$(nvram set wan_dns=${newwdns})"
                killall -HUP "init"
        [ -f "${pidfile}" ] && exit 1
        nvhost="$(nvram get wan_hostname)"
        [ "${nvhost}" ] && nvhost="-H $nvhost"
        nvlog="$(nvram get log_events)"
        [ "${nvlog}" != "${nvlog/dhcpc/}" ] && nvlog="-S"
        [ "${nvlog}" != "-S" ] && nvlog=""
        nvmin="$(nvram get dhcpc_minpkt)"
        [ "${nvmin}" = "1" ] && nvmin="-m"
        [ "${nvmin}" != "-m" ] && nvmin=""
        nvcustom="$(nvram get dhcpc_custom)"
        "$(udhcpc -R -b ${nvhost} -i br0 -p ${pidfile} -s ${rootfile} ${nvlog} ${nvmin} ${nvcustom})"
    exit 0
  2. BHTeam

    BHTeam Network Guru Member

    Can't you just put a static IP on the access point?
  3. B.S.

    B.S. Serious Server Member

    Of course you could ... but if you changed the subnet of the gateway, then you would have to redo it, ideally before the gateway change. This way it just follows the gateway. It shows up nicely in the DHCP client table as well.
  4. BHTeam

    BHTeam Network Guru Member

    Well, still don't get the point of having this script run and consume cycles, but hey everybody is limited by their own imagination :)
  5. mstombs

    mstombs Network Guru Member

    The script is only run when triggered so not a resource issue (unlike those folk that have expensive scripts continuously running to indicate wireless activity!)

    Allowing the router to request its own lan IP from another server is an old standard feature in adsl modem/router firmware I use


    and I agree this feature is just missing from tomato, would be a nice addition to the vlan version.

    I also didn't know you could add extra scripts like that to Tomato jffs, have always just used links from the scripts in the web gui, so thanks B.S. for useful contribution.
  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