Bulk upload DHCP static IP MAC mapping in EdgerouterX

Updating the Name of static IP/MAC mapping is not allowed in the GUI and there is no easy way to do these changes in bulk. With the approach below, you can also update the assignment of IP and organise things to your hearts content.

  1. Format the existing mapping into a tab delimited format in the order of Name, IP and MAC. You can get the existing mapping by downloading the config file.
  1. Copy the entries from config.boot file.
            static-mapping name1 {
                ip-address 192.168.0.49
                mac-address xx:xx:xx:xx:xx:xx
            }
            static-mapping name2 {
                ip-address 192.168.0.126
                mac-address xx:xx:xx:xx:xx:xx
            }
  1. Convert this to tab delimited format using Sublime text or Notepad.
name1	192.168.0.49	xx:xx:xx:xx:xx:xx
name2	192.168.0.126	xx:xx:xx:xx:xx:xx
  1. Tweak the bulk import code (script.x) from here using the order of your leases.txt, LAN name and subnet.

ubnt@router:~$vi script.x

#!/bin/vbash
source /opt/vyatta/etc/functions/script-template
configure

while read name ip mac
do
set service dhcp-server shared-network-name LAN subnet 192.168.0.0/24 static-mapping $name ip-address $ip
set service dhcp-server shared-network-name LAN subnet 192.168.0.0/24 static-mapping $name mac-address $mac	
done < leases.txt
     
commit
save
exit
  1. Paste the tab delimited text.

ubnt@router:~$vi leases.txt

  1. Delete the existing static mapping.
ubnt@router:~$delete service dhcp-server shared-network-name LAN subnet 192.168.0.0/24 static-mapping
  1. Run the script.

ubnt@router:~$sh script.x

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.