Dynamic Hostname Setting

I've got a number of Unifi WAPs in service. Some of them are going EOL in the new year, so I'm looking to move to a more long term solution rather than buy new WAPs.

I've got a test unit set up how I'd like, except for the unit's hostname. I'd like it to be OpenWRT-202917, where the last 6 digits are the last 6 digits of the LAN interface's MAC address.

I've got a number of these WAPs and I'd like to avoid manually changing each one's hostname.

I know solutions like OpenWisp2 exist, but I've not been able to get that running (yet) on my docker swarm.

The final question:
Is there a way to dynamically define the $HOSTNAME variable, and if so, is there a way to do so without having to write a custom startup script?

Not sure this is the best solution, but I've found this:

echo OpenWRT-$(ip addr | grep link/ether | head -1 | cut -d' ' -f 6 | cut -d":" -f4-6 | sed 's/://g') > /proc/sys/kernel/hostname

Works to set the hostname as desired. Place this line in the "Local Startup" text box and hit reboot. Should do the job.

Make it permanent:

uci set system.@system[0].hostname=the_name
uci commit system
service system restart
1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.