Automatically Sync DHCP Leases to Dumb Access Points

Hi everyone,

I want to share a solution I recently developed that allows both the MAC address and hostname to be displayed under "Associated Stations" on dumb access points, similar to the way the main router does this. This way, you can easily identify which devices are connected to each access point. The solution involves automatically syncing DHCP leases data from the main router to multiple dumb access points.

Use case:

  • A main router
  • One or more dumb access points (that only handle WiFi)

Here's the step-by-step solution:

  1. Generate SSH Key Pair:
  • On the main router, run the following command to generate an SSH key pair:
dropbearkey -t ed25519 -f /etc/dropbear/private_key -y /etc/dropbear/public_key
  • Ensure the private key has the correct permissions:
chmod 600 /etc/dropbear/private_key
  1. Copy Public Key to Access Points:
  • Append the contents of the public key file (/etc/dropbear/public_key) to the /etc/dropbear/authorized_keys file on each dumb access point. This enables passwordless SSH access from the main router to the access points.
  1. Create Sync Script:
  • Create a shell script file, for example, sync_dhcp_leases.sh, on the main router with the following content:
#!/bin/sh

# List of access points to sync with
access_points="192.168.1.2 192.168.1.3 192.168.1.4"

# Path to the dhcp.leases file on the main router
dhcp_leases_file="/tmp/dhcp.leases"

# Destination directory on the access points
destination_dir="/tmp/"

# Path to the SSH private key
ssh_private_key="/etc/dropbear/private_key"

# Loop through each access point and copy the dhcp.leases file
for access_point in $access_points; do
    scp -i "$ssh_private_key" "$dhcp_leases_file" "root@$access_point:$destination_dir"
done
  • Save the script and make it executable:
chmod +x sync_dhcp_leases.sh
  1. Schedule Script Execution:
  • Open the crontab for editing:
crontab -e
  • Add the following line to run the script every half hour:
*/30 * * * * /path/to/sync_dhcp_leases.sh
  • Save and close the crontab file.

Remember to adjust the paths and IP addresses in the script to match your setup and append ' /path/to/sync_dhcp_leases.sh' to '/etc/sysupgrade.conf' so it is preserved during an upgrade and in your backup archive.

With these steps in place, the script will automatically sync the DHCP leases data from the main router to the specified dumb access points. You will be able to see both the MAC address and hostname under "Associated Stations" on the access points, making it convenient to identify connected devices.

Please feel free to ask any questions or share your experiences with this solution!

6 Likes

You should add this to the Wiki, users inquire about this often.

Good idea lleachii, I asked the wiki admins to create a wiki account for me.

3 Likes

On reviewing the wiki I discovered that other solutions have already been posted here, one of which is very similar to my approach but simpler in that it uses a oneliner cron job.

You can find links to the posts here:
Populate Host Names in Associated Stations

2 Likes