1
General Discussion / Re: dhcp static mappings import using modified backup-file
« on: August 28, 2018, 08:18:16 am »
It works now. I missed the <staticmaps>-tags for each host
If anyone needs to read out host entries from an isc-dhcp-server, too, here is my script ...
I copied the scripts output into the special sections of the OPNsense-backup-file an reimported that. To be sure about the needed structure it is useful to create some entries before. At least the script saved me a lot of time ...
Cheers
If anyone needs to read out host entries from an isc-dhcp-server, too, here is my script ...
Code: [Select]
#!/bin/bash
# read active ip-addr from isc-dhcp-server and write xml-structure for opnsense
# etries in dhcpd.conf looks like:
# host 110-100 { hardware ethernet 00:25:90:cd:0d:98; fixed-address 192.168.110.100; } # my comment
dhcpin=/etc/dhcp/dhcpd.conf
dhcpout=$(hostname)-dhcp-4-opnsense.xml
grep '^host' $dhcpin | while read line
do
echo " <staticmap>" >> $dhcpout
mac=$(echo $line | cut -d '{' -f 2 | cut -d ' ' -f 4 | cut -d';' -f 1)
echo " <mac>$mac</mac>" >> $dhcpout
ip=$(echo $line | cut -d ';' -f 2 | cut -d ' ' -f 3)
echo " <ipaddr>$ip</ipaddr>" >> $dhcpout
hn=$(echo $line | cut -d ' ' -f 2)
echo " <hostname>$hn</hostname>" >> $dhcpout
beschr=$(echo $line | cut -d '#' -f 2)
echo " <descr>$beschr</descr>" >> $dhcpout
echo " </staticmap>" >> $dhcpout
done
I copied the scripts output into the special sections of the OPNsense-backup-file an reimported that. To be sure about the needed structure it is useful to create some entries before. At least the script saved me a lot of time ...
Cheers