Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

OpenWRT static IPv6 DUID auto-assign script
#1

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:
#!/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: kavove-zrnka-lajna.jpg]
Coffee phreak!
Reply




Users browsing this thread: 1 Guest(s)