How to nicely make a neighbors discovery solicitation on Linux?
I am looking for a way to retrieve the MAC address of a specific host on a LAN network. I know its IPv6 address. Ideally I would like a way to trigger the Linux Kernel to perform the neighbor solicitation for me, then I could retrieve the host MAC address through the command ip -6 neighbour
Right now, the only way I found to trigger a neighbor solicitation is to try to establish a TCP connection to the host on a random port. But I do not find this solution really pretty:
curl --connect-timeout 1 "http://[fe80::1234%eth0]:12345"
Solution 1:
Due to your requirement for this to be reflected in the kernel's neighbors, and your reluctance to install software, try ICMP echo:
ping -c 1 fe80::1234%eth0
Does not really matter what protocol you attempt, so long as it is IP based.
If you are willing to install software, nmap has discovery features. Here is a NDP only scan, output to a XML file (and stdout) which includes the link layer address:
nmap -sn -PR -oX /tmp/lladdr.xml -6 fe80::1234%eth0
Apparently, this type of nmap scan tickles the kernel to do neighbor discovery, as in testing I see it reappear under ip neigh
.
Solution 2:
ndisc6 -1 fe80::1234 eth0
Replace eth0
with the correct interface name, of course.