2

is there a tool/daemon available that automatically fills /etc/ethers in the background with the proper hostname:mac pairs to have a up to date database when needed with for example wake on lan (wol) ? maybe something that does not "scan" the network, but cassually dumps the arp cache or something ?

thanks

  • 1
    Try arpwatch as a starting point – roaima Jan 7 '16 at 22:19
  • oh thats already a good one! thanks for the tip. does not yet fill the /etc/ethers , but keeps track of everything required. – Axel Werner Jan 7 '16 at 23:01
0

A tool that will handle the majority of this is arpwatch. By default (on Debian, at least) is that it writes to /var/lib/arpwatch/arp.dat. This file is flushed and updated each time arpwatch is stopped.

The file contains entries of this form:

52:54:00:aa:bb:cc  192.168.1.2  1452252063  somehostname  eth0

The /etc/ethers file requires only the MAC address and either the IP address or resolvable hostname:

52:54:00:aa:bb:cc  192.168.1.2

It is then quite straightforward to keep /etc/ethers updated and in sync with a small script, run daily from crontab:

#!/bin/bash

# Flush arp.dat
service arpwatch restart

# Save a copy
test -f /etc/ethers || touch /etc/ethers
cp -fp /etc/ethers /etc/ethers.old

# Check to see if anything new has arrived. If so rebuild the file
(
    echo '# This file is updated automatically from /var/lib/arpwatch/arp.dat'
    echo '# Take care when editing'
    echo '#'
    (
        awk '{print $1,$2}' /var/lib/arpwatch/arp.dat
        grep -v '^#' /etc/ethers.old
    ) |
        sort -u
) >/etc/ethers.tmp

# Update ethers with the new file
cmp -s /etc/ethers.tmp /etc/ethers || cat /etc/ethers.tmp >/etc/ethers
rm -f /etc/ethers.tmp

# All done
exit 0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.