[SOLVED] How to dynamically configure /etc/network/interfaces on boot with ubuntu upstart
UbuntuThis forum is for the discussion of Ubuntu Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to dynamically configure /etc/network/interfaces on boot with ubuntu upstart
I'm running Ubuntu 14.04 LTS 64 bit, in a VirtualBox VM. Sometimes I bring up my laptop with only the integrated Ethernet card connected, other times I bring it up with an additional USB-to-Ethernet device connected. I would like to essentially use two different network interface configurations. One with eth0 set to DHCP when there's only one interface, and another with eth0 configured to a static IP, and eth1 set to use DHCP.
It took me a while to learn that Ubuntu doesn't use the typical System V or BSD style init scripts, but actually uses it's own event driven Ubuntu Upstart system, which will also call the System V style scripts as well.
I thought I could put a script in the /etc/netowrk/if-pre-up.d folder, which would automatically generate the correct content of /etc/network/interfaces, and then when "ifup -a" is called later in the "pre-start script" section of /etc/init/networking.conf that everything would work.
Instead what I find is that the /etc/network/interfaces file is correctly generated when I switch back and forth, but when I go from 2 interfaces to 1, eth0 comes up boots with the old static IP even though /etc/network/interfaces clearly shows it should be configured as DHCP. Likewise when I go from 1 interface to 2, eth1 properly comes up as DHCP but eth0 does not come up with the static IP which is configured in /etc/network/interfaces. Also Ubuntu get's stuck on the splash screen "Waiting up to 60 seconds for network configuration" and "Waiting up to another 60 seconds for network configuration". Also this may be relevant, I completely uninstalled the network-manager service. Perhaps the networking upstart is somehow dependent on it?
I assume there is some kind of issue with ubuntu upstart but I'm not sure how to troubleshoot it, or how to correctly configure the upstart scripts to do what I want. Does anyone have an idea of how to properly accomplish this?
I doubt that it's an upstart problem, but can't be certain since I've avoided the mainline Ubuntu distribution ever since it changed from Gnome to the Unity desktop. Fortunately Xubuntu is still based on GTK principles, and the kernels are basically the same.
However it's my understanding that all variants of Ubuntu now use the Network Manager applet, rather than the /etc/network/interfaces file, to handle network configuration. As I recall, that happened back around version 10.04.
I originally edited my /etc/default directory to add two files for Network Manager and Network Manager Dispatcher, each containing the single command "exit" and nothing else. The files in this directory are sourced as the very first action when each package is initialized, and these two files caused the Network Manager and its dispatcher to quit without initializing themselves. That left the field free for the older interfaces file to do its thing, and worked quite well.
However when I did a fresh install to 14.04 earlier this year, I decided to see whether the Network Manager applet had solved its original problems, and it seems that it has -- for me.
I don't see any simple way for it to deal with your requirement, however. You might try my original solution to take Network Manager out of the picture, and see whether the interfaces file then works as you want it to. If you do, let us know your result -- it might help someone else.
The Upstart approach seemed like overkill to me when I first encountered it, but over the years I've come to appreciate some of its advantages over the original Sys-V approach. However it's apparently in the process of being replaced by "systemd" and so we're getting far removed from the initialization techniques we learned originally!
I was able to solve this issue. The root case was a timing issue with, when my script was run vs., when the "ifup" command was run. Ifup which configures the interfaces based on the contents of /etc/network/interfaces was being run first before my script which generates the /etc/network/interfaces files. I was able to troubleshoot it and find the root cause by adding "logger <message>" lines to each of the scripts running at boot time, and then inspect the /var/log/syslog file. Clearly, this is one of the major downsides to Ubuntu upstart. The increased parallelism can cause all kinds of timing issues which are difficult to troubleshoot.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.