NI Linux Real-Time Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Switch from static to dynamic IP on secondary NIC without restart?

"When changing IP settings, we do an ifconfig  down/up. I tried setting a static IP on a 9068 and didn't see an ARP broadcast. However I was able to ping the target on the static IP."

How is that possible if you do not see any ARP broadcasts? On my network the computers will not have updated their ARP cache due to the lack of an ARP broadcast from the target...so in order for me to be able to ping the device I have to force an ARP update. I can wait for the ARP cache timeout to kick in, but that takes a long time (10 minutes on Windows 8). As mentioned I do get it to work if I run ip link set up/down afterwards from the admin account...which should be equivalent to an ifconfig down/up(?).

"If you're already on the right device, you don't need ssh. ssh is good for remote access from one device to another. If you just want to change users, the command to consider is "su":http://man7.org/linux/man-pages/man1/su.1.html".

I tried running sudo...but it returns as not supported. That's why I turned to ssh (I do not really want to need to know the password though...).

0 Kudos
Message 11 of 18
(1,761 Views)

ifconfig and ip link set are somewhat equivalent but work differently.

In order to get arping to run automatically when changing network settings, you can do the following.

Run opkg update && opkg install iputils-arping on the target, then add a call to arping to the up case of /etc/ifplugd/ifplugd.action.

Message 12 of 18
(1,761 Views)

I tried running sudo...but it returns as not supported. That's why I turned to ssh (I do not really want to need to know the password though...).

I mentioned su (not sudo) because it is installed by default, and with it you can do things like "su -c" which are similar to sudo. su will require the password of the user you're becoming, though (admin in this case). sudo is in the package feed, and could avoid that: it usually requires the password of the user running sudo, but you can configure sudoers to not require a password (search for NOPASSWD in the docs).

0 Kudos
Message 13 of 18
(1,761 Views)

ScottSalmon wrote:
"If you're already on the right device, you don't need ssh. ssh is good for remote access from one device to another. If you just want to change users, the command to consider is "su":http://man7.org/linux/man-pages/man1/su.1.html"

If I run the su command from system exec it returns "su: must be run from a terminal". So no luck there. I have added arping and it works when I run it via ssh on the admin account, but have not yet figured out how to build and issue the correct command using the ifplugd script.

Ideally I guess I should be able to add the necessary actions more directly (the ARP update happens if I run ip link down/up for example) in a script somewhere...I'm not yet familiar enough with Linux though (Linux RT on the 9030 is my first encounter...).

0 Kudos
Message 14 of 18
(1,761 Views)

That's right, I forgot about that restriction on su and how it would interact with System Exec. I apologize for not testing within System Exec before posting. I should have just gone with sudo as the recommendation from the start. See my post above yours. Then a command line like "sudo whoami" in System Exec works and returns "admin" in stdout.

0 Kudos
Message 15 of 18
(1,761 Views)

FYI - having installed sudo and given the lvuser rights to run the arping command, I found out that using arping to send a gratitous ARP after changing the IP address with the System Config API did not work after all. It returns the error: "bind: Cannot assign requested address".

Probably because other parts of the system has not really registered that the IP address has been changed either..(it does if you plug and unplug the network cable for example).

However, doing an ip link down/up cycle initiated the necessary update (and then the arping command is not necessary).

0 Kudos
Message 16 of 18
(1,761 Views)

Further testing with self-reconfiguration of the NIC config using System Config API has shown that even running ip link down/up has its problems. Sometimes it works, sometimes it does not.I'll be spending some time now checking if I can get it more stable by adding waiting time between different operations for example.

It seems that the System Config API should be doing a bit more than it is, at least on the sbRIO-965... - When it returns that no restart is required for the given reconfigurations it leaves out that you still need to unplug and replug the network connection for the changes to come into effect. If you change the addressing from DHCP to static for example, and save, the DHCP client continues to send out DISCOVER messages - until the connection is unplugged and plugged. Only then does it start using the static configuration.

0 Kudos
Message 17 of 18
(1,761 Views)

I have now been able to implement a stable self-reconfiguration (switching between DHCP and static depending on DHCP server availability) using the System Config API combined with sudo ip link down (only).

I used to do ip link up after down, but it turns out that everything works best/ as it should with just the down command (perhaps someone from NI knows why the up command is not necessary, and also seem to cause instabilities when used?).

I hope the System Config API will be updated someday so that it is no longer necessary to install sudo and run the ip command to get changed effectuated, but for now I'm happy that it is at least possible to get around that limitation.

0 Kudos
Message 18 of 18
(1,761 Views)