DHCP / IP vs Physical Addr

Hi there,

I am new to OpenHAB, but work with java dev. daily.

“Please note: if your network devices use a DHCP server to obtain ther IP addresses automatically, please make sure to define a DHCP reservation for a device which you want to use in openHAB. Otherwise it’s IP address may change in the future and your thing definiton won’t work any more. Information about how to define a DHCP reservation can be normally be found in the manual of your network router.”

Why not simply lookup the phys addr. and use that to recognize the device in place of the IP? I like the way DHCP works :slight_smile:

That is find the ip:

ping 192.168.1.1 (or whatever)

And then find the MAC addr via the ARP table.

All done in java code of cause.

https://www.mkyong.com/java/how-to-get-mac-address-in-java/

mvh

Nikolaj Hansen

How would the software find the IP address for the external network device (the 192.168.1.1) if it is dynamically assigned? The code you referenced finds the MAC for the local default NIC.

Yes, that is a working strategy to lookup a network devices. I’m using this here to find my Amazon Echo which cannot be pinged and does not have any open ports. However, as steve1 already mentioned, your Java code just gets the MAC address of your local network interface. You have to lookup the MAC address in the ARP cache of your OS (as you correctly wrote in your post).

Yes, you can find the MAC address of a network device using platform-dependent techniques. Since the quote from the documentation was related to the OH2 network device discovery I thought the question was “why does openHAB not use this technique?”. AFAIK, there’s no Java platform-independent way to do a reverse/inverse ARP query. @Temar, what technique are you using to query the ARP cache? Do you do anything to ensure the Echo’s MAC is actually in the cache?

Yes I do. My DNS server runs on that machine as well, so the Amazon Echo actually has to talk to it :slight_smile:

I’m using a shell script to query the ARP cache.

Hi all,

Thank you for your answers.

I know the example queries the local NIC, I just figured you could pass any IP on the same subnet. I should probably read the javadoc…

I have read several places that the ARP table is available on many routers and gateways using SNMP. I know that is possible from java. It should probably be fetched from whatever device holds the DHCP table.

Another way is to use one of the arpd servers available. But that is not a clean java solution.

with regards

Nikolaj Hansen

Hi all,
why are you not using the standard way ?
Using DHCP/DNS with names ? Using layer2 methods is always very environment dependend and upgly.
Use static DHCP and assign proper names to your DNS.

e.g. DNSMASQ:
dhcp-host=set:router,a0:20:a6:01:4b:07,192.166.253.10,NODE-14B7,5m

Cheers
Chrimo

Hi,

When it comes to IP networking and DNS I don’t think there is a “standard” way.

Some chose to give their devices a fixed ip, and update the dns server with this entry. You chose to do, more or less, the same by giving a static IP assignment to a MAC address via DHCP.

You still have to maintain a list of all the devices in either case. In addition to the list of devices in OpenHAB.

with regards

Nikolaj Hansen

What’s up? Could anyone help me understand how this dhcp work?
I want to have remote access to my rpi out of the network and I don’t want to use my openHAB neither the static ip add. so I wold like to make only the right settings in my router! The proplem is that this stupid router I have is from the tv/internet local provider (ZTE) and it doesn’t aloud me to assign an static dhcp according to rpi MAC address and the desired ip! And than let’s say if I could do that, what next? How do I access the internal ip binded to the rpi mac add. ? do I need to port forward? I didn’t understand this procedure very well even it sounds very easy! I used to have access out of the local network by using a static ip in my rpi, opening port 8080 and using a dns which was free and now it isn’t anymore!
What about duckdns? I can’t use it because I can’t fill the internal ip in the ipv6 space! I’m using ipv4 but it says it works with both ip types but I couldn’t set one.
Thanks!