What's new

Feature request - DHCP reservations from csv file

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

wayner

Regular Contributor
I just recently upgraded from a very old version of Merlin so I did a factory reset and started from scratch. This meant lots of typing. I am also trying to get my IP addresses a little more organized as I have lots of devices on my LAN - close to 100 devices.

One thing that would be hugely beneficial, at least from my perspective, would be the ability to upload a csv file to your router and use this to created DHCP reservations (and also port forwards).

You could easily generate the CSV file by copying data out of a LAN inventory from a program like WakeMeOnLan and then use Excel to easily generate the IP addresses sequentially or whatever you want. Then just save this as an IP file and upload it to your router's jffs partition, or even just have a big text block where you can paste the CSV file.

The CSV file would look like this:
Code:
MAC address,IP Address,Hostname
A0:30:A6:0D:76:4E,192.168.1.200,WifiLightKitchen
B8:27:EB:BC:F0:2C,192.168.1.201,RasbPi1

Is this doable?

If so then I would make the same suggestion for port forwarding.
 
Someone could probably whip up a shell script to do the same thing, with far less work than implementing this in the router itself. Parse the CSV, and convert it into an nvram setting.
 
Ok, I will give this a go then. It looks like the nvram setting that needs to change is dhcp_staticlist.

What is the command to append something to nvram dhcp_setlist?

Maybe the easiest way to do this is to generate the file in whatever means you would want (I would use excel), transfer it to the jffs folder and then run a shell script to append it to nvram dhcp_setlist.

Rather than using CSV it might even be easier to generate text in the format that dhcp_static list seems to use, as in
Code:
<A0:30:A6:0D:76:4E>192.168.1.200>WifiLightKitchen<B8:27:EB:BC:F0:2C>192.168.1.201>RasbPi1
 
You can't append, so you have to retrieve the existing content, and merge it with any new content before writing it back.

And yes, at this point you might as well write it directly in native format, as the format isn't that complex:

Code:
<MAC>IP>Hostname
 
@merlin - How does this look? Assuming that you have the new DHCP reservations in a file called dhcp_add.txt then shouldn't the following work?
Code:
nvram get dhcp_staticlist | tr -d'\n' > dhcpnew.txt
cat dhcp_add.txt >> dhcpnew.txt
nvram set dhcp_staticlist="$(cat dhcpnew.txt)"

I pipe the contents of the current list into dhcpnew.txt while trimming the \n from the file. Then I am appending the new list onto the file and resetting the list from the contents of the file.

When does the router actually read the nvram and take the action to update the hdcp reservations with the values in the nvram? Do I have to issue a command to do that?
 
You could also just use a custom dnsmasq conf add-on file - which is where the dhcp reservations end up?
 
@merlin - How does this look? Assuming that you have the new DHCP reservations in a file called dhcp_add.txt then shouldn't the following work?
Code:
nvram get dhcp_staticlist | tr -d'\n' > dhcpnew.txt
cat dhcp_add.txt >> dhcpnew.txt
nvram set dhcp_staticlist="$(cat dhcpnew.txt)"

I pipe the contents of the current list into dhcpnew.txt while trimming the \n from the file. Then I am appending the new list onto the file and resetting the list from the contents of the file.

When does the router actually read the nvram and take the action to update the hdcp reservations with the values in the nvram? Do I have to issue a command to do that?

Just have to restart dnsmasq to make this change immediately effective.

Code:
service restart_dnsmasq
 
And it looks like the actual data goes partially into the /etc/ethers file, for the MACs and IPs and then the hosts.dnsmasq file for the IPs and friendly names.
 
Sorry, maybe I was thinking of Tomato where the entries do go in the conf file, I recall you can also define multiple macs to the same Ip, for example when a laptop can have both wireless or wired connections with same IP - not at same time. You could do this with asuswrt-merlin, but may lose usefulness of the management gui - relevant info is is the source-code example file

https://github.com/RMerl/asuswrt-me.../src/router/dnsmasq/dnsmasq.conf.example#L219

How to use custom additions to conf files:-
https://github.com/RMerl/asuswrt-merlin/wiki/Custom-config-files

I was thinking that you could manage the file on a PC and just copy to router and it would save nvram...
 

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top