Auto-IP address configuration on OpenWRT

First you need to install the avahi autoipd.

opkg update
opkg install avahi-autoipd

Then add the script '50-autoipd' to '/etc/hotplug.d/iface/'.

# create avahi state directory
mkdir -p /var/lib

[ ifup = "$ACTION" ] && {
	[ -n "$DEVICE" ] && {
		AUTOIP_OPT=$(uci -q get network.${INTERFACE}.autoip)
		[ "${AUTOIP_OPT}" == "yes" ] && {
			avahi-autoipd -D ${DEVICE}
		}
	}
}

[ ifdown = "$ACTION" ] && {
	[ -n "$DEVICE" ] && {
		AUTOIP_OPT=$(uci -q get network.${INTERFACE}.autoip)
		[ "${AUTOIP_OPT}" == "yes" ] && {
			avahi-autoipd -k ${DEVICE}
		}
	}
}

Finally, configure your interface (/etc/config/network) as 'none' without an IP address and set the 'autoip' option to 'yes'.

config interface 'dtn'
        option proto 'none'
        option autoip 'yes'
Last modified 6 years ago Last modified on 11.09.2013 13:15:14