hookenz
hookenz

Reputation: 38947

How can I programatically set the IP address of a hardware device that doesn't already have an IP set

We have developed a hardware device that doesn't have a screen. It uses TCP/IP to communicate with the network. Currently this is configured by DHCP.

However, we'd like a way to configure it's IP statically by some app I'll have to develop. I notice for some devices like printers there are custom apps that they use to set such information. But how do they talk to the device when the device hasn't been assigned an IP already?

Are they using RAW sockets and a custom protocol? or is there a simpler method. For example, I recall many years ago using a Linux device that somehow received it's initial IP by running an arping. But I don't understand how that sets the IP for other hosts on the network. Nevertheless it seemed to work. Could I mimick that?

e.g. arp -s 191.168.2.2 00-40-9d-22-23-60

So I've got an idea how it works, but I'd like to know what is the common method of setting IP to an embedded device that has no physical screen to configure this.

To be clear, this device does not use Linux.

Upvotes: 2

Views: 127

Answers (1)

tofro
tofro

Reputation: 6073

The standard-conformant way of doing this goes (for IPv4, but IPv6 is similar) along the lines of:

  1. Try to obtain an IP address via DHCP, skip step (2) if that worked. This should be the default.
  2. If no DHCP server responded, use a unique link-local address (These are addresses from the block 169.254.0.0/16 reserved for this purpose. Some parts of the chosen address should be based on something unique to the device, like the MAC address, to make sure the device always chooses the same LL address. Or, to make it fully RFC-compliant: choose a truly random address from this range and probe it - Re-use it when possible) The chosen LL address should be checked against any other use in this network before usage with an arp request on that address (That's probably what you have read). If someone responds to that request, choose a different IP and retry.
  3. Now that you have a temporary IP address, you can use one of the various IP-Multicast-based service discovery protocols to advertise your device to the network.

Upvotes: 3

Related Questions