Well to be fair, everyone says "arp -a", but I am not satisfied with this answer, since it only shows the known MAC addresses (and their corresponding IP).
To list all addresses on a port, you'll need to change your current network configuration. We will use the bridge-utils package, but any other bridge implementation (eg.: OpenvSwitch) can do this. The following description will work on Debian based systems:
- First you should install the bridge-utils package.
- Set the selected port down with ifdown
- Create a bridge on the port you want to list the MAC addresses
Let's assume the port is eth0, and the IP address is dynamic. In /etc/network/interfaces the following should appear
allow-hotplug eth0
iface eth0 inet manual
auto br0
iface br0 inet dhcp
bridge-ports eth0
bridge_fd 0
bridge_stp off
To apply these changes, you can either use ifup on eth0 and then on br0, or simply restart.
- Now you can use brctl to query the port
It will list the full MAC table:
root@debian:~# brctl showmacs br0
The output should look something like this:
port no mac addr is local? ageing timer
1 ab:cd:ef:01:02:03 no 1.72
1 ab:cd:ef:01:02:04 no 25.52
1 ab:cd:ef:01:02:05 no 2.64
1 ab:cd:ef:01:02:06 no 10.67
1 ab:cd:ef:01:02:07 yes 0.00