OpenWRT static IPv6 DUID auto-assign script

Bash skripty
User avatar
Ashus
Administrátor
Posts: 410
Joined: 07. 07. 2007 10:51
Location: Ostrava - Polanka nad Odrou
Contact:

OpenWRT static IPv6 DUID auto-assign script

Postby Ashus » 13. 12. 2015 22:05

The script and idea was based on jhnphm's post here.
The idea is to assign client's DUID addresses (IPv6) just like MAC addresses for IPv4 to the config file. The prerequisite is to have odhcpd configured and IPv6 prefixes filled for DHCP clients via LuCI. Since the DUID is required for static IPv6 to work and there are no fields in LuCI, you can use the script after the client is seen for the first time (probably configured dynamically).

Code: Select all

#!/bin/sh

for I in $(uci show dhcp|awk -F '(\\[|\\]|\\.|=)' '{if ($2=="@host" && $5=="name") print $6}'); do # find existing static host entries and find hostnames
    NAME=$(echo -ne $I | sed -r "s/'//g")
    DUID=$(cat /var/hosts/odhcpd |awk -F ' '  "{if (\$1 == \"#\" && \$5 == \"$NAME\") print \$3 }"|head -n 1)  # find duid for existing hostname in leases
    ID=$(uci show dhcp|awk -F '(\\[|\\]|\\.|=)' "{if (\$2==\"@host\" && \$6==\"$I\") print \$3}") # Find placement of host entry
        if [ "$DUID" != "0000000000000000000000000000" ]; then
                echo Found: $NAME = $DUID
                uci set dhcp.@host[$ID].duid=$DUID # Set DUID
        fi
done
echo Commiting changes.
uci commit
killall -HUP odhcpd
Image
Coffee phreak!

Who is online

Users browsing this forum: No registered users and 1 guest

cron