Associate MAC address with configurable name

Hi,

*** EDITED and changed hostname to configurable name ***

Does anyone know how I can associate MAC addresses with a configurable name?

Mable-Notebook 192.168.0.108 88:53:xx:xx:xx:xx 1h 30m 42s
? 192.168.0.237 e8:9d:xx:xx:xx:xx 1h 30m 42s
android-3c13f80a78e8da54 192.168.0.158 ec:9b:xx:xx:xx:xx 0h 2m 59s
RedmiNote2-Redmi 192.168.0.184 20:82:xx:xx:xx:xx 1h 56m 2

My current DHCP table looks like the above. Not very useful, especially, when there's the "?" as a host name, and "android-3c13...". I can't get on those hosts to give them names, so I would like a way to name them somewhere on the router, without having to give them a specific IP address.

Ideas?

2 Likes

You can't associate MAC addresses with hostnames, however.

You can create static DHCP leases, thereby assigning a reserved IP address to DHCP requests originating from a specific MAC address. With this, you can additionally also create local DNS entries (overrides) for your domain (.lan, by default) to point towards your local (or even remote) IPs. The combination of these two should provide you with the desired functionality.

Using luci, both are easily available (in a combined form) via "Network" --> "DHCP and DNS" (/cgi-bin/luci/admin/network/dhcp) under "static leases" (it also allows setting up IPv6 suffixes and MAC specific lease times).

2 Likes

Thanks, slh.

What I meant wasn't a hostname. I meant a configurable name that makes sense.

And without having to assign a static DHCP lease.

That defeats the purpose of having DHCP.

Not really, static DHCP leases (configured on the DHCPd, not the clients) are a primary functionality of (enterprise-) DHCP setups.

If your client does submit its hostname as part of the DHCP request, dnsmasq will remember it and the MAC address mapping dynamically - however neither will survive a reboot, nor does that allow editing the assignment.

Which is why I'd like something that can associate a name with a MAC address.

When I bought a Linksys WRT1900AC, it has this functionality, and the functionality is not DHCP.
It doesn't depend on the IP address as well.

1 Like

Yes it is possible to force a name for a DHCP client.

Got to LuCI => DHCP and DNS => General Settings => Static Leases, set hostname and mac-address and you're done.

I'm using this feature for clients not sending a hostname via DHCP.

3 Likes

I think what he actually wants is to display the name in a way that's more human-readable(by configuring it). not to actually change the hostname given by DHCP

2 Likes

True and I especially request that feature too.
I'm using my openwrt devices as dumb APs that connect a l2-network to wifi.
The DHCP-server is residing on another device, but I still want to show proper hostnames in the wifi-stats.

2 Likes

A dumb AP does not handle DHCP requests, it just passes the packet to the main router, so it does not have any information about client names. It would have to somehow request that information from the DHCP, and as far as I know, there isn't a protocol to handle such requests... not an easy task.

Why are people talking about DHCP requests???

This is not a DHCP request. This is just to request a configurable name to be displayed beside the device on the DHCP area of the OpenWRT.

Do people not read?

This would be the logic:

if Dictionary.TryGet(DeviceMac, Name) then
DeviceItem.Name := Name;

What the above means is that look in the dictionary for a key matching the device mac address, and if it matches, retrieves the value and place it into the variable Name.

If that succeeds, in the device item display on the OpenWRT, assign the name to the name column.

If I knew how to modify OpenWRT, or any Lua script, I would be able to do this in a few minutes.

Here's what I need, for people who have difficulty visualizing or reading/understanding what I wrote

Mac Address | Host Name | IP Address | Configurable Display Name
40:22:33:44 | XyZAndroid | 192.168.1.1 | My Android hand phone

4 Likes

What dictionary are you talking about?

You are asking to modify the page where DHCP information is being displayed, but those who talk about DHCP are who do not read?

Haven't you noticed I was answering to @Double-G, not you?

If I dare saying that I read and understood your request, at least for me, I edited the file /etc/dnsmasq.conf and add lines like:

dhcp-host=11:22:33:44:55:66,MyBelovedDevice

1 Like

When you edit /etc/dnsmasq.conf and use the dhcp-host option, you're associating host name with the mac address.

Again, I am not talking about hostname.

The DHCP page is the only place where the mac address shows up.

Fortunately / unfortunately, the time for associating a configurable display name (not hostname) has passed, so I will not be pursuing this any more.

If I would work on this, I would be editing the DHCP page, and when it is being displayed, I would lookup existing mac address that have been given a lease, and then read another file, where mac addresses and associated display names are stored.

Then, I would store the mac address and the associated display names in a lookup table.
Then for each mac address that have a lease, I would lookup in the lookup table, get the display name, and display it.

This algorithm doesn't require any sending or receiving any DHCP requests, since all the mac addresses that have a lease are already stored somewhere in a file.

The OpenWrt method would be to:

  • edit /etc/config/dhcp
  • use the UCI commands; or
  • add the Static Lease in the LuCI web GUI.
config host
	option name 'MyBelovedDevice'
	option mac '22:33:44:55:66'

I understand the OP rather use a non-standard name through some self-made script (i.e. something that doesn't exist in out-the-box OpenWrt), so this doesn't help with the OP's chosen method to solve the problem.

3 Likes

Coincidentally, I'm looking for the same thing as OP, but I'd go a bit further and associate multiple MAC addresses and also a description and other metadata.

I'll probably look into UCI schemas and see if there is a straight forward way to augment LuCI with different device display names if the app is installed.

I'm back to OpenWRT after a long hiatus and in the intervening decade the number of devices on my network has grown significantly. We have a longstanding hostname convention that's becoming difficult for my aging brain to keep track of (and impossible for the rest of the people on the network).

RADIUS accounting ?

Pre-authorize section could be used for desired name calling.

I'm not sure I'm following. Effectively I want a directory of devices that have made dhcp requests or lan to wan access. That directory would have the sole purpose of being a reference for keeping track of arbitrary metadata concerning the connected device - a "display name" being one the possible fields; user, device type, location, etc. possible other fields.

This data wouldn't be known to the host at all and the names and other data given wouldn't be used for anything but reporting (what devices haven't been annotated before), querying(what are all of person 1's devices), automation, and making personal reference easier.

I don't really care to configure RADIUS when the majority of information I want is available passively through DHCP and wan access.

For example, "Active DHCP Leases", "Active DHCPv6 Leases", and "Associated Stations" all have lists of hosts, but all display different data and none of them allow "drilling down" into the details OpenWRT has about a specific host. It would be great to click on any of the entries, get the metadata described above, any relevant logs or other info for the device.

You’ll need to pull it from somewhere. RADIUS allows this type of querying. If you just want to crossreference with an existing list, you’ll find some suggestions above. It’ll be your own custom solution.

And here's a prototype, written in Lua:

function dump(o)
    if type(o) == 'table' then
        local s = '{ '.. string.char(10)
        for k, v in pairs(o) do
            if type(k) ~= 'number' then
                k = '"' .. k .. '"'
            end
            s = s .. '[' .. k .. '] = ' .. dump(v) .. string.char(10)
        end
        return s .. '} '.. string.char(10)
    else
        return tostring(o)
    end
end

HostData = {}
function HostData.new(macAddr, ipAddr, hostname, description)
    return { MacAddress = macAddr, IP = ipAddr, HostName = hostname, 
             Description = description }
end

Dictionary = {}
hostdata = HostData.new("12:34:56:78", "192.168.1.1", "MyLaptop1", "My first Powerful Laptop")
Dictionary[1] = hostdata
hostdata = HostData.new("78:34:56:12", "192.168.1.2", "MyLaptop2", "My SuperDuper laptop")
Dictionary[2] = hostdata
print("dictionary: ", dump(Dictionary))

and when you run it, here's what it shows:

dictionary:     { 
[1] = {
["Description"] = My first Powerful Laptop
["HostName"] = MyLaptop1
["IP"] = 192.168.1.1
["MacAddress"] = 12:34:56:78
}

[2] = {
["Description"] = My SuperDuper laptop
["HostName"] = MyLaptop2
["IP"] = 192.168.1.2
["MacAddress"] = 78:34:56:12
}

}

When I wrote the original post, I didn't know Lua.

And therefore, with the prototype code, I've shown it's possible to associate MAC addresses with hostnames, add descriptive names to MAC, IP addresses or hostnames, or do whatever funky stuff you want.

So, what really remains to be done is to flesh out the idea further, and some kind of editor to edit the data (if it's needed, or just get the data somewhere) then incorporate it into Luci and OpenWRT and submit a PR.

1 Like

Thanks for that. While poking around more, I noticed that the page for the router itself has many of the fields already present. I'll spend a little more time looking at it in the coming weeks.