Table of static DHCP-Leases

Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware
Goto page 1, 2  Next
Author Message
hoogasch
DD-WRT Novice


Joined: 01 Mar 2009
Posts: 3
Location: Kiel, Germany

PostPosted: Mon Mar 02, 2009 10:18    Post subject: Table of static DHCP-Leases Reply with quote
Hi,
is there a possibillity to edit the table of static DHCP-Leases (accesible via the Services-tab in the GUI) easily with the command-line or to upload a predefined *.txt-file? The point is, that it is quite nasty (and boring) to fill every single field in the table manually when there are many changes at one time (especially when you are doing copy& paste from e.g. MS Excel).
Thanks for helping me,
Holger
Sponsor
DrRossi
DD-WRT Novice


Joined: 14 Nov 2006
Posts: 31
Location: Rotterdam, The Netherlands

PostPosted: Mon Mar 02, 2009 15:05    Post subject: Re: Table of static DHCP-Leases Reply with quote
Static leases are apparently stored in the nvram variable "static_leases"

So with "nvram get static_leases" you can see your current static leases.

http://www.dd-wrt.com/wiki/index.php/Hardware

Explains how to use the "nvram" command

so it appears to be quite easy.
redhawk0
DD-WRT Guru


Joined: 04 Jan 2007
Posts: 11563
Location: Wherever the wind blows- North America

PostPosted: Mon Mar 02, 2009 15:59    Post subject: Reply with quote
There are actually 2 variables involved. One is the total number of leases...the other is the leases themselves

nvram set static_leasenum=2
nvram set static_leases="00:11:22:33:44:55=name1=192.168.1.10 00:11:22:33:44:56=name2=192.168.1.11"
nvram commit

redhawk

_________________
The only stupid question....is the unasked one.
hoogasch
DD-WRT Novice


Joined: 01 Mar 2009
Posts: 3
Location: Kiel, Germany

PostPosted: Mon Sep 21, 2009 14:02    Post subject: Reply with quote
Thanks a lot. I tried it and in general it works. Now I experienced some following problems, so could you just have a look here: http://www.dd-wrt.com/phpBB2/viewtopic.php?p=351397#351397?
metrux
DD-WRT Novice


Joined: 07 Jun 2006
Posts: 2

PostPosted: Wed Oct 14, 2009 11:22    Post subject: Reply with quote
Hi,

I'm thinking about a small script for adding dhcp static leases and adapting access restrictions. Or think about RADIUS
rakstr
DD-WRT User


Joined: 12 Feb 2010
Posts: 65

PostPosted: Fri Feb 12, 2010 18:06    Post subject: Reply with quote
Has anyone scripted this? Would be great if you could feed it something like comma separated list to enter all the reservations.
dirk
DD-WRT User


Joined: 04 May 2008
Posts: 79

PostPosted: Fri Feb 12, 2010 23:49    Post subject: Reply with quote
Yes. I am using a ruby script to generate static DHCP assignments for a couple of routers from a config file.

I'm generating a configuration file for dnsmasq, though.
rakstr
DD-WRT User


Joined: 12 Feb 2010
Posts: 65

PostPosted: Fri Feb 12, 2010 23:56    Post subject: Reply with quote
dirk wrote:
Yes. I am using a ruby script to generate static DHCP assignments for a couple of routers from a config file.

I'm generating a configuration file for dnsmasq, though.


Will you be posting that?
redhawk0
DD-WRT Guru


Joined: 04 Jan 2007
Posts: 11563
Location: Wherever the wind blows- North America

PostPosted: Sat Feb 13, 2010 0:35    Post subject: Reply with quote
BTW...the format for the static_leases parameter has changed.

00:11:22:33:44:55=name1=192.168.1.10=1440 00:11:22:33:44:56=name2=192.168.1.11=2880

is now the correct format....the last number is the lease time in minutes.

if left blank

00:11:22:33:44:55=name1=192.168.1.10=

then the lease is indefinite.

This has changed with the 13832 build.


redhawk

_________________
The only stupid question....is the unasked one.
dirk
DD-WRT User


Joined: 04 May 2008
Posts: 79

PostPosted: Sat Feb 13, 2010 9:38    Post subject: Reply with quote
rakstr wrote:
Will you be posting that?


No, it's about 3000 lines of code that is very specific to my VPN setup. Here's the relevant code that updates dnsmasq:

Code:
def update(network, keyfile)
    dhcp_options = <<-END
dhcp-option=lan,44,10.10.10.102
dhcp-option=lan,45,10.10.10.102                             
dhcp-option=lan,46,8
server=/100.10.10.in-addr.arpa/10.10.100.1
server=/10.10.10.in-addr.arpa/10.10.100.1
server=/100.10.in-addr.arpa/10.10.100.1   
#{network.to_dhcp(LEASE_TIME)}
    END
    startip = network.dhcp_first_ip
    endip = network.dhcp_last_ip

    str = <<-END
interface=br0
resolv-file=/tmp/resolv.dnsmasq
domain=#{network.name}.#{domain.name}
server=/100.10.10.in-addr.arpa/10.10.100.1
server=/10.10.10.in-addr.arpa/10.10.100.1
server=/100.10.in-addr.arpa/10.10.100.1
dhcp-leasefile=/tmp/dnsmasq.leases
dhcp-lease-max=#{network.dhcp_num}
dhcp-option=lan,3,#{network.router.internal}
dhcp-option=lan,44,10.10.10.102
dhcp-option=lan,45,10.10.10.102
dhcp-option=lan,46,8
dhcp-authoritative
dhcp-range=lan,#{startip},#{endip},255.255.255.0,#{LEASE_TIME}
#{dhcp_options}
END

    printf("   Connecting")
    Net::SSH.start(network.router.dyndns, 'root', {:keys =>[keyfile], :port => network.router.dyndns_port}) do |ssh|
        scp = ssh.scp

        # changed to SCP upload because length of command that can be
        # used in ssh.exec! seems to be limited
        vpn_push = <<-END
nvram set dnsmasq_enable=1
nvram set dns_dnsmasq=1
nvram set auth_dnsmasq=1
nvram set dhcp_start='#{network.dhcp_start}'
nvram set dhcp_num='#{network.dhcp_num}'
nvram set dnsmasq_options='#{dhcp_options}'
END
        scp.upload!(StringIO.new(vpn_push), "/tmp/vpn_push.sh")
        printf(".")
        $stdout.flush
        ssh.exec!("/bin/sh /tmp/vpn_push.sh")
        ssh.exec!("rm /tmp/vpn_push.sh")
        printf(".")
        $stdout.flush
        ssh.exec!("nvram commit") do |ch, res|
            raise "Failed to commit to nvram" unless res
            printf("c")
            $stdout.flush
        end

        scp.upload!(StringIO.new(str), "/tmp/dnsmasq.conf")
        ssh.exec!("rm /tmp/dnsmasq.leases")
        printf(".")
        $stdout.flush
        ssh.exec!("killall dnsmasq")
        printf(".")
        $stdout.flush
        ssh.exec!("dnsmasq --conf-file=/tmp/dnsmasq.conf")
        puts(". done.")
    end
end


Basically, what it does is:
    Generate a new configuration file for dnsmasq
    Upload that file with scp to the router
    Delete the old leases file (required if leases change)
    Restart dnsmasq with new configuration

The only problem is that you need to have a short lease time because clients do not know about any ip changes until their lease expires. I have set LEASE_TIME to one hour.
Force4
DD-WRT Novice


Joined: 24 Aug 2007
Posts: 34

PostPosted: Sat Feb 13, 2010 10:55    Post subject: Reply with quote
You can also use the DNSMask textarea in Services tab to setup your static leases.

I do it like this: DNSMask Options:

domain=local
expand-hosts
dhcp-host=00:A1:B2:C3:D4:E5,Comp1,10.0.0.1,infinite
dhcp-host=00:F1:G2:H3:I4:J5,Comp2,10.0.0.2,infinite
...
rakstr
DD-WRT User


Joined: 12 Feb 2010
Posts: 65

PostPosted: Sat Feb 13, 2010 14:29    Post subject: Reply with quote
Force4 wrote:
You can also use the DNSMask textarea in Services tab to setup your static leases.

I do it like this: DNSMask Options:

domain=local
expand-hosts
dhcp-host=00:A1:B2:C3:D4:E5,Comp1,10.0.0.1,infinite
dhcp-host=00:F1:G2:H3:I4:J5,Comp2,10.0.0.2,infinite
...


I get all that but I'm looking for an improvement to the GUI. Like I orginally pointed out, every other SOHO router I've ever used, and there have been many, allow you to automatically populate a DHCP reservation from the connected clients table. I REALLY cut's down on typing and errors. It's very useful. How do we request features for D-WRT? Is there a thread for that discussion?

Thanks folks. BTW, I can't upload yet, too few posts, but I wrote a shell script to parse a hosts-like file that will populate the static_leases. If anyone wants it, PM me.
yzy-oui-fi
DD-WRT Guru


Joined: 03 Mar 2009
Posts: 2826
Location: France

PostPosted: Sat Feb 13, 2010 14:37    Post subject: Reply with quote
redhawk0 wrote:

is now the correct format....the last number is the lease time in minutes.


Dummy question....Why to have a lease time for static lease?
I mean for what kind of reason this could be usefull?

Anyway It's interesting to know this change.

_________________
DD-WRT WDS MESH + DASHBOARD (fr), DD-WRT network setting tool (tools.yzy-oui-fi.com), Wifi Business and IT guy After hours, My Blog, Free DD-WRT VPN Community(www.wrt-pptp-ww.com), DD-WRT pré-réglés pour réseau outdoor(hotspot.yzy-oui-fi.com), Nouveau Forum DD-WRT francophone
redhawk0
DD-WRT Guru


Joined: 04 Jan 2007
Posts: 11563
Location: Wherever the wind blows- North America

PostPosted: Sat Feb 13, 2010 14:47    Post subject: Reply with quote
yzy-oui-fi wrote:
redhawk0 wrote:

is now the correct format....the last number is the lease time in minutes.


Dummy question....Why to have a lease time for static lease?
I mean for what kind of reason this could be usefull?

Anyway It's interesting to know this change.


Personally...I think its a useless feature. I have mine set to blanks so it is still Indefinite.

It's a feature...useless, but a feature. :lol:

redhawk

_________________
The only stupid question....is the unasked one.
yzy-oui-fi
DD-WRT Guru


Joined: 03 Mar 2009
Posts: 2826
Location: France

PostPosted: Sat Feb 13, 2010 15:10    Post subject: Reply with quote
maybe this will change back next release Wink
_________________
DD-WRT WDS MESH + DASHBOARD (fr), DD-WRT network setting tool (tools.yzy-oui-fi.com), Wifi Business and IT guy After hours, My Blog, Free DD-WRT VPN Community(www.wrt-pptp-ww.com), DD-WRT pré-réglés pour réseau outdoor(hotspot.yzy-oui-fi.com), Nouveau Forum DD-WRT francophone
Goto page 1, 2  Next Display posts from previous:    Page 1 of 2
Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum