How to view dnsmasq client MAC addresses dynamically?

5,208

In man page of dnsmasq there is a option saying

-l, --dhcp-leasefile=<path>
    Use the specified file to store DHCP lease information.

So, you can use a file to log it. And the format of the file is:

 946689575 00:00:00:00:00:05 192.168.1.155 wdt 01:00:00:00:00:00:05
 946689522 00:00:00:00:00:04 192.168.1.237 * 01:00:00:00:00:00:04
 946689351 00:0f:b0:3a:b5:0b 192.168.1.208 colinux *
 946689493 02:0f:b0:3a:b5:0b 192.168.1.199 * 01:02:0f:b0:3a:b5:0b

Fields of each row:

 1) Time of lease expiry, in epoch time (seconds since 1970). BTW you
 seem to be living in the past: most of us are well past 1000000000
 seconds by now :-) . There are compile time options in dnsmasq which
 convert this field to be remaining lease time (in seconds) or, in the
 most recent releases, total lease renewal time.

 2) MAC address.

 3) IP address.

 4) Computer name, if known. This is always unqualified (no domain part)

 5) Client-ID, if known. The client-ID is used as the computer's
 unique-ID in preference to the MAC address, if it's available. Some DHCP
 clients provide it, and some don't. The ones that do normally derive it
 from the MAC address unless explicity configured, but it could be
 something like a serial number, which would protect a computer from
 losing its identify if the network interface were replaced.

The order of the lines has no significance, and will change over time.

Share:
5,208

Related videos on Youtube

dotslash
Author by

dotslash

Updated on September 18, 2022

Comments

  • dotslash
    dotslash almost 2 years

    If I have already known the client IP, I know there's /var/log/dnsmasq.log and it contains logs such as

    Jun 13 12:22:42 dnsmasq-dhcp[499]: DHCPACK(wlan0) 172.24.1.110 34:12:98:11:80:bd ones-iPad
    Jun 13 13:19:44 dnsmasq-dhcp[499]: DHCPDISCOVER(wlan0) d4:97:32:61:4f:73
    Jun 13 13:19:44 dnsmasq-dhcp[499]: DHCPOFFER(wlan0) 172.24.1.82 d4:97:0b:61:4f:23
    Jun 13 13:19:44 dnsmasq-dhcp[499]: DHCPREQUEST(wlan0) 172.24.1.82 d4:97:9f:61:4f:73
    Jun 13 13:19:44 dnsmasq-dhcp[499]: DHCPACK(wlan0) 172.24.1.82 d4:97:0b:23:4f:73 android-ef9f423f7ecaca3c

    In router

    In this way, we can parse the log every time to see the latest MAC address.

    But can we know what the client mac without parsing this long big file every time. It drags down CPU.

    Thank you!


    updated

    I found another place containing it

    cat /var/lib/misc/dnsmasq.leases

    Still it's a file. Or I have to parse the file every time?

  • dotslash
    dotslash about 8 years
    Thank you! It looks it's at here /var/lib/misc/dnsmasq.leases by default. And someone suggest me can use dhcp-script with it. Maybe I can use a temporary sqlite3 database to store the sequence of leases. But that's a bigger thing but easy to search specific IP or MAC.
  • BillThor
    BillThor about 8 years
    @dotslash Try grep..