Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

[This is for Debian Squeeze, but applies to Ubuntu and other Linux distros.]

I have a rather complex /etc/network/interfaces file which is generated based on various factors (number of interfaces, are bridges needed, vlans, etc). After the new file is generated, I need to ifup any new interfaces and ifdown any obsolete interfaces; and I might have to reboot if the primary interface changes (for example, it changes from eth0 or br0).

Right now I figure out what to ifup/ifdown manually.

Is there a script that will do this for me?

share|improve this question

3 Answers 3

I don't know how you currently modify/generate your /etc/network/interfaces. Probably the best solution would be to use a configuration management tool (such as Puppet, Chef or Cfengine) to do this task, and have it call ifup when the file is modified. Such tools are tailored for tasks like this one. You could even benefit from Puppet's templating capabilities or the Augeas provider to modify your file.

Another solution would be to use inotify. For examople, you could set up incron to call ifup every time /etc/network/interfaces is modified.

share|improve this answer
    
Actually I'm using Puppet (and a template) to generate the file. If the template changes and an interface is no longer needed, I want to ifdown it before the file changes (or ifdown won't know how to down it... quite a PITA) –  TomOnTime Mar 11 '12 at 18:16
    
What if you made puppet backup the old version of the file, and called a script in refreshonly mode? This script would then play with the two files, putting back the old one, running ifdown, and putting the new file again. That sounds a bit complex, but I think it would work for you. –  ℝaphink Mar 12 '12 at 6:42
    
The ideal situation would probably be to make a Puppet provider for netcf at some point… –  ℝaphink Aug 21 '12 at 10:04

I don't know of any readily available script for this use-case, but hacking together a simple shell script for this task shouldn't be too hard.

share|improve this answer

This is how I manage ifcfg files with puppet. I create a directory under files/ for each host, e.g.:

modules/network/files/foohostname/
modules/network/files/someotherhostname/

Then in modules/network/manifests/init.pp I do the following:

  1. Copy all files in modules/network/files/hostname/ to the network scripts directory on the host.
  2. Run service network start or /etc/init.d/network start when any files are added/changed. I've found that service network start will bring up any interfaces that are not up yet, but won't kill my existing network connections.
class network {
  # copy all ifcfg files from files/hostname/ directory to network-scripts/ 
  # other files in network-scripts/ will not be touched.
  file { '/etc/sysconfig/network-scripts/':
      recurse => true,
      purge   => false,
      owner   => root,
      group   => root,
      ignore  => '\.svn', # this is specific to me as I use svn.
      source  => "puppet:///modules/network/${hostname}/",
  }

  # if anything changes with the above File resource, then fire network start to bring them up.
  # this won't restart the network, only bring up any ifaces that are not up yet.
  exec{ 'network-ifup':
      command     => 'service network start',       
      refreshonly => true,
      subscribe   => File['/etc/sysconfig/network-scripts/'],
  }        
}

FYI some of the above may be a little CentOS/RHEL-specific.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.