I have a very typical situation in which I want to connect an (android) phone to a linux notebook in the same (wifi) network using ssh. The IP's are assigned by DHCP so I know only the one of the client in advance. Knowing the IP of the client I could in principle loop a ssh command over all possible IP's in the same net to see if a server is listening there. However this seems highly inefficient. So, how can I figure out the IP of my host (knowing it's MAC address) so I can connect to it using ssh? I know about other software which achieves something like this so it must be possible. Related: can I dynamically assign a hostname to this IP on the client (assuming it is Linux) so that I can use a static entry in the ssh config file?
You can do it in the following two steps:
Scan your subnet to fill your ARP cache. There are methods but I suggest
...then scan your network (for example, subnet 192.168.10.0/24):
Now the ARP cache is filled with MAC address of devices in your subnet.
Apply an appropriate filter on your ARP cache to just see target device. Just use following command (where
The output is the IP address of target device.
Sample MAC address has been changed to lower case because Linux shows it in this manner (unlike Microsoft Windows using upper case)
Following bash script add an entry to hosts file (
Zeroconf might be a solution here. It is a protocol to discover services on the network and establish a link between two hosts.
If you set up avahi mDNS (packages
It sounds like your problem is that you're plugging something into the network and you want to be able to know what IP it will get.
On that basis it sounds like the simplest possible solution is to configure your DHCP server to give out a static IP for the appropriate MAC address.
Do you have control over the DHCP server? If so you could probably do one of two things: