Automated replacement of /etc/network/interfaces
Home › Forums › Conduit: mLinux Model › Automated replacement of /etc/network/interfaces
- This topic has 4 replies, 2 voices, and was last updated 4 years, 9 months ago by
Martin Bures.
-
AuthorPosts
-
February 17, 2022 at 3:22 pm #32568
Martin Bures
ParticipantI am trying to build an automated installer script to flash our gateways with the Senet Packet forwarder. I am having trouble replacing the /etc/network/interfaces file so that I can turn off the static ip address on 192.168.2.1 and have it listen to dhcp on 192.168.1.x.
When I try to do this with a script – either with sed or by directly replacing the file, it does not seem to persist. When I do it manually with vi, it works.
Do you have any thoughts on how to accomplish this?
February 18, 2022 at 12:51 pm #32569Jeff Hatch
KeymasterHello Martin,
Could you post the code that you are trying to do this with, both the “replacing” code and the sed code? Maybe someone can help you fix the code if there is something incorrect.
Jeff
February 23, 2022 at 11:09 am #32576Martin Bures
Participant#!/bin/sh
ntpdate pool.ntp.org
sed -i -e ‘s/yes/no/g’ /etc/default/lora-network-server
sed -i -e ‘s/static/dhcp/g’ /etc/network/interfaces
sed -i -e ‘s/address/#address/g’ /etc/network/interfaces
sed -i -e ‘s/netmask/#netmask/g’ /etc/network/interfacescat /etc/default/lora-network-server
cat /etc/network/interfaces | grep dhcp -C 8/etc/init.d/networking restart
February 23, 2022 at 2:08 pm #32578Jeff Hatch
KeymasterHello Martin,
I figured out how mLinux may be thwarting your editing via script. There is a script “/etc/init.d/config” that creates links to all the configuration files since I believe that /etc is not writable on some systems (I am not sure why mLinux is behaving in this manner other than on mLinux upgrades the /var/config directory and partition there don’t get overwritten). Anyway, I believe that your script is actually overwriting the link and not the file the link points to, ie. instead of editing the file /etc/network/interfaces->/var/config/network/interfaces, it is reading the resolved linked file “/var/config/network/interfaces”, editing it, and then writing to /etc/network/interfaces creating a new file. This works as expected.
However, upon reboot, the /etc/init.d/config script runs and since /etc/network/interfaces is not a link it blows /etc/network/interfaces away and creates the link described in the previous paragraph.
To address this try editing the file in /var/config/network/interfaces instead. That way it should persist.
Thank You,
Jeff
February 23, 2022 at 4:06 pm #32579Martin Bures
ParticipantTHANK YOU.
I will take a look at this.
Best Regards.
Martin. -
AuthorPosts
- You cannot reply to this topic.