HiDefLoLife HiDefLoLife - 4 months ago 19x
Linux Question

Why would /etc/network/interfaces be empty after programmatic changes and subsequent reboot?

I run a node.js server on an embedded device which provides a web UI to allow users to modify network interface settings - for example, changing from Static to DHCP or vice versa, or setting specific Static IP settings (netmask, gatetway), etc. With these user-driven configuration parameters, I am able to programmatically generate a new /etc/network/interfaces file (of course, after backing the previous file to /etc/network/interfaces.bak file). I even do a 'cat /etc/network/interfaces' to the log file of the new configuration file to confirm the new interfaces file's contents and syntactic validity. So far, everything is hunky-dory.

However, if there is a reboot on my device (with or without a /etc/init.d/networking stop/start prior to reboot), I find that many times the system comes up with an empty /etc/network/interfaces file and, therefore, no network interfaces. (Fortunately, I have a JTAG interface allowing SSH connection and so still have connection to my device but to users their device is essentially bricked.)

What would cause the OS to blank the /etc/network/interfaces file? I think this must be done during system initialization - but for what reason?

If I make the same changes manually using a text editor and reboot, everything is fine - the new interface settings come up every time.

I am at a loss to explain what might be causing this behavior.


Here are other factors that I considered but have ruled out:

  • Perhaps the file isn't saved properly? I've ruled this out because
    the cat command would indicate it was successfully saved.

  • Perhaps there are other files (or persistent settings) that need to be modified, without which the configuration is considered invalid and blanked? I've ruled this out because my understanding is that the interfaces file is the only configuration required for interface setup.

  • Perhaps there are syntatic errors in the interfaces file. I've ruled
    this out because I've compared my programmatic output to valid files
    and things look fine. Furthermore, I don't think syntatic errors
    would cause a file to be blanked.

EDIT: My device is based on a TI Sitara uP running a Debian Wheezy 3.14 variant. I run node.js v0.12.x as the server backend.


It's possible that the modified file wasn't flushed to the disk and remained in a cache. The cat command could have read the file from that cache.

Try using sync (see here) to force a flush to the underlying storage.