[这是Debian Squeeze,但适用于Ubuntu和其他Linux发行版。]
我有一个相当复杂的/ etc / network / interfaces文件,它是根据各种因素(接口的数量,是否需要桥接,vlans等)生成的。 新文件生成后,我需要ifup任何新的接口和ifdown任何过时的接口; 如果主接口更改(例如,它从eth0或br0更改),则可能必须重新启动。
现在我想出手动ifup / ifdown。
有一个脚本可以帮我吗?
我不知道你目前如何修改/生成你的/etc/network/interfaces 。 可能最好的解决scheme是使用configurationpipe理工具(如Puppet,Chef或Cfengine)来完成这个任务,并且在文件被修改时调用ifup 。 这些工具是为这个任务量身定制的。 您甚至可以从Puppet的模板function或Augeas提供程序中获益以修改您的文件。
另一个解决scheme是使用inotify。 对于考官来说,每次修改/etc/network/interfaces都可以设置incron来调用ifup 。
我不知道这个用例是否有任何可用的脚本,但是为这个任务攻击一个简单的shell脚本应该不会太难。
这就是我用puppetpipe理ifcfg文件的方法。 我在每个主机的files/下创build一个目录,例如:
modules/network/files/foohostname/ modules/network/files/someotherhostname/
然后在modules/network/manifests/init.pp我做到以下几点:
modules/network/files/hostname/中的所有文件复制到modules/network/files/hostname/上的networking脚本目录中。 service network start或/etc/init.d/network start 。 我发现service network start会带来任何尚未service network start接口,但不会中断现有的networking连接。 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/'], } }
仅供参考上面的一些可能是CentOS / RHEL特定的一点。