OpenWrt: Client host names for access points

To increase 5GHz wireless coverage in my home network, I bought a used GL.inet MT6000 (Flint 2), installed OpenWrt and configured it to be a dumb access point.

One thing bothered me: The web interface shows the list of connected clients - but only their MAC address, and no host names or IP addresses.

This is a known problem and documented on the OpenWrt wiki page in section Populate Hostnames in Associated Stations as well as many forum threads, e.g. Associated stations - making hostnames visible across multiple APs and Show hostname in Associated stations

My solution

/etc/ethers

I wanted to popuplate the /etc/ethers file on the access points.

My network has many devices with statically configured IP addresses; I keep a list of them in my Documents folder. Other devices get their IP by DHCP, and dnsmasq running on my home server had a mapping of MAC to IP addresses in /etc/dnsmasq.d/cweiske-dhcp.conf with lines like

dhcp-host=00:22:F4:CB:32:D3,gamestick,192.168.3.41

After reading about /etc/ethers I converted most of those dnsmasq configuration entries into ethers lines. Then I only needed to add the read-ethers config option to /etc/dnsmasq.d/cweiske-dhcp.conf to make dnsmasq use it.

The dnsmasq dhcp-host entries require IP addresses, which I already maintain in /etc/hosts. Converting to ethers let me get rid of the duplication.

The only thing not supported with ethers is having the same IP address for multiple MACs, which I want for the laptops - they can be used wired or wirelessly, and they should alwas have the same IP and hostname. For them I still have entries in the dnsmasq configuration:

dhcp-host=E2:A6:05:1A:E3:45,00:00:00:00:B0:00,boo,192.168.3.5

Generating ethers

Sometimes devices connect that have no entries in my hard-coded list of MAC and IP addresses, and they should also be visible in the access points.

dnsmasq leases are written down in /var/lib/misc/dnsmasq.leases and can be converted into ethers-style with

awk '{print $2 " " $4;}' /var/lib/misc/dnsmasq.leases

Combining my manually managed ethers file with the leases is easy, as well as copying them to the access points:

/etc/cweiske-distribute-ethers.sh
#!/bin/sh
#distribute /etc/ethers to the openwrt access points
# so that the web interface shows the host names
tmpfile=/tmp/ethers-openwrt
 
echo "# provided by dojo" > "$tmpfile"
echo -n "# generated " >> "$tmpfile"
date -Is >> "$tmpfile"
 
cat /etc/ethers |grep -v -e '^#' -e '^$' >> "$tmpfile"
awk '{print $2 " " $4;}' /var/lib/misc/dnsmasq.leases >> "$tmpfile"
 
accesspoints="ap-wz ap-buero"
for ap in $accesspoints; do
    scp -o BatchMode=yes -o ConnectTimeout=5 "$tmpfile" root@$ap:/tmp/ethers &
done

I made this script executable with chmod +x and configured dnsmasq to call it with

dhcp-script=/etc/cweiske-distribute-ethers.sh

Then I configured each access point to accept my home server's SSH key via the web interface and installed the openssh-sftp-server package, which is required for scp to work.

/tmp/ was chosen to reduce wear on the flash drive - tmp lives in RAM. So the last thing I had to do was logging into each access point and symlinking /etc/ethers to /tmp/ethers:

$ ssh root@ap-wz
$ rm /etc/ethers
$ ln -s /tmp/ethers /etc/ethers

Result

The OpenWrt web interface now shows the host names of all connected clients:

Associated Stations #1 Associated Stations #2

Written by Christian Weiske.

Comments? Please send an e-mail.