Join 3,418 readers in helping fund MetaFilter (Hide)


Planning for telnet on DHCP
January 7, 2013 11:20 AM   Subscribe

I need some help on networking and ip addresses. I'm working on a project that uses a RN-XV Wifly module to connect to a home's wifi network. To use the device you will have a GUI that on the back-end telnets to the Wifly module and sends a serial string of commands. So if the Wifly address is 10.1.0.17, it would send:

telnet 10.1.0.17 80
(text commands)
ctrl^] (escape character)
quit

If you are using static ips on your home network, no problem. But if you use dhcp, which is the standard out-of-the-box for just about every wireless router out there...

I don't know how people usually handle dhcp. Here's the order of events that concerns me.

1. Plug in device, it gets an IP address assigned from the wifi router using dhcp.
2. Get the IP address and write it into the script.
3. The script works, everything works, no problem.
4. Someone unplugs the device, and when it is plugged back in the router gives it a different dhcp address.
5. Now the script doesn't work because it is telneting to the wrong ip address.

What is the best practice for handling that case? Is there a unique identifier you can assign to a device that abstracts the ip address? Like if I do "telnet bob 80" and something somewhere knows "bob" is 10.1.0.17, where it is smart enough that if the ip address changes, "bob" changes too?

Thanks. I'm hoping for a solution that require no setting changes to the router, so changing to things like "dhcp and static ips" is not what I hope to do.
posted by BeeDo to Computers & Internet (14 answers total)
 
What I have seen most devices do is provide a software utility that runs on your PC/Mac and will scan and find the device/IP.

If it has internet access, you could have it phone home to a server and have a web page that lists the local IP there.
posted by wongcorgi at 11:37 AM on January 7, 2013


Is there a unique identifier you can assign to a device that abstracts the ip address? Like if I do "telnet bob 80" and something somewhere knows "bob" is 10.1.0.17, where it is smart enough that if the ip address changes, "bob" changes too?

This is called DNS. You can set up a local dynamic DNS server, but that's more trouble than just setting up the device on static ip.

You can also set up the device on static ip without changing the router. The average home network only has a half dozen devices at most, which gives you about 200 addresses to play with on the upper end of the dhcp range with very little risk of conflict.
posted by empath at 11:40 AM on January 7, 2013


I think what you want is some kind of service discovery beyond DHCP. There are off-the-shelf protocols that can be used. Failing that, you could use TCP/IP multicast to have the script broadcast a message to everything on the subnet, but that's likely to annoy people if it gets deployed on something other than a home LAN. Some routers will also respect local DNS hostname requests, but my anecdotal experience with that on my Linksys router is that it's very fragile.
posted by qxntpqbbbqxl at 11:42 AM on January 7, 2013


If you use a router that uses Dnsmasq as its DHCP and DNS server, when a device gets an IP from DHCP it will register that device's hostname in DNS. So given your "bob" example above, you set your device to have "bob" as the hostname and you can indeed do "telnet bob 80". I use this all the time both at home and work and it works very well.

I know that ASUS's line of routers that use their Asuswrt firmware have dnsmasq out of the box. Such devices are the RT-N16, RT-N66U, and RT-N66AC. Dnsmasq is also part of DD-WRT, so if you have a router that supports DD-WRT you may be in luck.
posted by zsazsa at 11:47 AM on January 7, 2013


The way I would solve your problem is that the device would contact a central server (e.g. on the internet or "in the cloud") on assignment of an IP address. The device would then register a unique device ID with the server, so that there is a connection between "current device IP" and "device ID". This can be done with an outgoing telnet session from the device, simulating HTTP. Oh, and you might want to blink a led as this happens, so that the user knows the device is online.

The "device ID" should be printed on the device itself. The first time the GUI starts it should ask for the device ID (for the user to type in), and for every startup it should query the central server for the local IP. This way the GUI app could (at least in theory) be some form of web app as well.

Your main problem would probably be that nearly all wifi networks uses authentication, in various forms, and this authentication would have to happen before the DHCP address is assigned.
posted by Baron Humbert von Gikkingen at 12:03 PM on January 7, 2013


Unless the Wi-Fly or your Arduino has a DHCP client that supports dynamic DNS, in which case you would have a hostname that the device itself could update its IP for, you want to use a DHCP reservation that ties an IP address to a particular MAC address for the device, so the Arduino/WiFly will always have the same internal IP. Consult your DHCP server's documentation for more information, most do have this capability.
posted by rhizome at 1:02 PM on January 7, 2013


DHCP reservations, or else try to set a static address on the WiFly (I'm not familiar with that box, so I'm not sure what it can do) and adjust the DHCP pool to be smaller so that the WiFly's static address never gets issued to another box while WiFly is offline.
posted by Sunburnt at 1:26 PM on January 7, 2013 [1 favorite]


I'm currently back to my ZTE modem, but the 2-Wire (which I think is now Pace) modem that I was using for some testing of fancy hardware on my ADSL2+ line a few months back was extremely good at remembering MAC addresses and always re-assigning the same DHCP address to a given MAC address. (Had a few other glitches, which is why I'm back to the ZTE, but I really liked that about it!)

You can also put a MAC address in a DHCP pool with 1 IP address on the DHCP server that comes with most Linux distributions, and a quick Google search suggests that Cisco gear can be made to give a specific DHCP address to a given MAC address.

How much control over your DHCP server do you have?
posted by straw at 1:48 PM on January 7, 2013


Why is this device set to DHCP? Give it a static IP. If not, you'll need to set your DHCP server to do a reservation to use the same IP.

One of the other, there's no other solution here. Well, there's DNS, but i imagine if getting DHCP to do a reservation is off the table, then DNS is also.
posted by damn dirty ape at 1:49 PM on January 7, 2013


Thank you, that's a ton of great stuff I hadn't thought of.

Most promising because it would be really easy: So if I set the ip address of the wifly to static and make sure I don't ship more than one of these to the same customer with the same ip address (you could have multiples of this device in your house), it should all just work with their router with dhcp? I'll test that when I get home.

So if the router is assigning dhcp from 10.0.1.1-10.0.1.200, and I use 10.0.1.100 - 10.0.1.200 static for my devices, everything would work as long as the router doesn't happen to have something on the exact ip I choose?

Is it correct to say that the first 3 digits have to match the router (in this case the 10, 0, and 1)? Or could I do 10.0.2.xxx and be sure to be free of conflicts?
posted by BeeDo at 2:15 PM on January 7, 2013


So if the router is assigning dhcp from 10.0.1.1-10.0.1.200, and I use 10.0.1.100 - 10.0.1.200 static for my devices, everything would work as long as the router doesn't happen to have something on the exact ip I choose?

This is correct, but I would highly, highly suggest that you tell the customer to change the dhcp range on the router, it's very simple on most routers.

Is it correct to say that the first 3 digits have to match the router (in this case the 10, 0, and 1)? Or could I do 10.0.2.xxx and be sure to be free of conflicts?

You kind of need to know how they're router is configured. This might work, it might not.

I would highly, highly suggest that you let the customer configure all of this stuff himself, tbh.
posted by empath at 3:01 PM on January 7, 2013


Affirmative, it is all configurable by the end user. I'm just investigating the easiest out of the box behavior for the nontechnical customer.

Thanks all.
posted by BeeDo at 3:21 PM on January 7, 2013


I would say that best practice is to use DHCP + service discovery protocols, the same way network-enabled printers work. This requires no configuration by the user, it will work on networks using any range of IP addresses, and there's no possibility of conflicts between devices even if you have multiples on the same network.

Bonjour is a pretty simple protocol, native to OS X, but there are lots of other implementations, including for Arduino, Windows and Linux. The way it would work is that the device would publish a service record (with addServiceRecord if you used the previously linked library) with a service type like "BeeDoDevice._http" or "BeeDoDevice._MyProtocol". The front-end would do a search for services of the same type, and get back a list of addresses, ports and any additional config info you want to include--one for each device on the network.
posted by jjwiseman at 6:02 PM on January 7, 2013 [1 favorite]


:+D No arduino, just a pic, and the features in the wifly.
posted by BeeDo at 6:26 PM on January 7, 2013


« Older For my partner's birthday (hap...   |  Can I really not use an Apple ... Newer »
This thread is closed to new comments.