08-12-2011 06:52 AM
We have a customer who wants to be able to manage the IPs of all his devices with DHCP, but the devices are expected to keep their IP forever after the DHCP server has been taken offline. Is this a behaviour we can support on a NI controller?
If it is not a configurable behaviour one alternative could be to have the controlelr self-configure to the last known IP if no such is aquired...but the Apply Network Settings VI does not seem to work if run on the controller itself. Is this correct?
Solved! Go to Solution.
08-17-2011 03:51 PM
Hi Mads,
NI devices don't have a way to do this, primarily because it would violate the DHCP protocol. If the devices kept addresses after the lease expired, then when the DHCP server came back online, it could potentially give an address that is in use to another device.
I would suggest, if possible, that you change the lease time on your DHCP server. If you set the lease time to 1 year (the max if I remember correctly), then as long the DHCP server comes on every now and then, you will never lose your lease.
-Jeff
09-21-2011 06:15 AM
Together with NI in Norway (thanks) I found a solution that allows us to implement the requested behaviour.
The main problem for us once we needed to override the default DHCP behaviour was the fact that the RT Apply Target Network Settings.vi does not work if it is set to target the same controller as it is running on. So how could we swap between DHCP and fixed? Well, as it turns out the network settings are also stored in the ni-rt.ini file. So here's what we do: When the controller starts we check if it is running in DHCP-mode. If not, we change this in the ni-rt.ini file and reboot - to see if the DHCP server is operational. If the controller is running in DHCP we check if the IP address is valid (i.e. outside the link local range). If it is not we read the last known IP address and write those as fixed in the ni-rt.ini file, and reboot.
An example of the INI-file sections:
For DHCP the section of the ni-rt.ini will look like this:
[TCP_Stack_Config]
DNS_Address=USE_DHCP
Gateway=USE_DHCP
IP_Address=USE_DHCP
Subnet_Mask=USE_DHCP
For a Static IP:
[TCP_Stack_Config]
DNS_Address=0.0.0.0
Gateway=10.0.18.1
IP_Address=10.0.18.13
Subnet_Mask=255.255.255.128
It would be nicer if the RT Apply Target Network Settings.vi would work for self-reconfiguration, but this saved the day for us at least in this case.