LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 10-01-2015, 04:58 PM   #1
mjl3434
Member
 
Registered: Sep 2003
Location: USA
Distribution: Ubuntu 20.04
Posts: 111

Rep: Reputation: 15
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?

Last edited by mjl3434; 10-01-2015 at 06:50 PM.
 
Old 10-01-2015, 11:46 PM   #2
JimKyle
Member
 
Registered: Dec 2001
Location: Oklahoma City, OK, USA
Distribution: Xubuntu 16.04 LTS
Posts: 214
Blog Entries: 1

Rep: Reputation: 39
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!
 
Old 10-05-2015, 11:38 AM   #3
mjl3434
Member
 
Registered: Sep 2003
Location: USA
Distribution: Ubuntu 20.04
Posts: 111

Original Poster
Rep: Reputation: 15
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
3 network interfaces - only works from boot with two interfaces enabled linux_driver Linux - Networking 4 11-26-2014 05:42 PM
[SOLVED] Dynamically generating /etc/network/interfaces file every time ifupdown is run D1ver Linux - Networking 2 03-12-2014 06:11 PM
raspberry pi configure networking /etc/network/interfaces casperdaghost Linux - Newbie 4 01-13-2014 05:39 AM
LXer: Ubuntu's Success Story: the Upstart Startup Manager (Linux Boot Camp p.2) LXer Syndicated Linux News 0 04-08-2010 09:00 PM
configure /etc/network/interfaces/ alsharifhoussam Linux - Networking 2 12-21-2006 07:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 08:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration