[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?
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 callifup
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 callifup
every time/etc/network/interfaces
is modified.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.
This is how I manage ifcfg files with puppet. I create a directory under
files/
for each host, e.g.:Then in
modules/network/manifests/init.pp
I do the following:modules/network/files/hostname/
to the network scripts directory on the host.service network start
or/etc/init.d/network start
when any files are added/changed. I've found thatservice network start
will bring up any interfaces that are not up yet, but won't kill my existing network connections.FYI some of the above may be a little CentOS/RHEL-specific.