Debian配置网络参数的时候可以定义一个或者多个PreUp,PostUp,PreDown,PostDown脚本,实现各种需求和功能,也有一个ifup.d 脚本丢下去就可以了,而openSUSE连网后执行的脚本则放在/etc/sysconfig/network/if-up.d/,它们是到/etc/sysconfig/network/scripts/的符号链接。唯独这个特立独行的CentOS/Fedora。只在/etc/sysconfig/network-scripts/{ifdown-post,ifup-post,ifdown,ifup}末尾对/sbin/ifdown-local /sbin/ifup-local /sbin/ifdown-pre-local /sbin/ifup-pre-local进行了简单调用
只能自己补完这系列脚本了
[bash]
#!/bin/sh
#/sbin/ifup-pre-local
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
if [ -z "$1" ]; then
echo $"usage: $0 <ifcf-file>"
exit 1
fi
CFGFILE="/etc/sysconfig/network-scripts/$1"
[ -f "$CFGFILE" ] && . $CFGFILE
FILES="/etc/sysconfig/network-scripts/preup-$DEVICE"
if [ -x "$FILES" ]; then
/bin/sh $FILES
fi
[/bash]
[bash]
#!/bin/sh
#/sbin/ifup-local
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
if [ -z "$1" ]; then
echo $"usage: $0 <net-device>"
exit 1
fi
FILES="/etc/sysconfig/network-scripts/postup-$1"
if [ -x "$FILES" ]; then
/bin/sh $FILES
fi
[/bash]
[bash]
#!/bin/sh
#/sbin/ifdown-pre-local
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
if [ -z "$1" ]; then
echo $"usage: $0 <net-device>"
exit 1
fi
FILES="/etc/sysconfig/network-scripts/predown-$1"
if [ -x "$FILES" ]; then
/bin/sh $FILES
fi
[/bash]
[bash]
#!/bin/sh
#/sbin/ifdown-local
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
if [ -z "$1" ]; then
echo $"usage: $0 <net-device>"
exit 1
fi
FILES="/etc/sysconfig/network-scripts/postdown-$1"
if [ -x "$FILES" ]; then
/bin/sh $FILES
fi
[/bash]
ifup-pre-local参数是配置文件 其他都是接口名。
补充完 这些脚本后 要在eth0 post up后执行动作
在/etc/sysconfig/network-scripts/下创建postup-eth0文件 +x 权限即可
[bash]wget https://dl-web.dropbox.com/u/3241202/apps/linux-tool/CentOS-IF-UP-DOWN-Local.tar.bz2
解压
chmod +x /sbin/*-local[/bash]
参考资料:
- http://linux-wiki.cn/wiki/%E7%BD%91%E7%BB%9C%E8%BF%9E%E6%8E%A5%E5%BB%BA%E7%AB%8B%E5%90%8E%E8%87%AA%E5%8A%A8%E8%BF%90%E8%A1%8C%E7%A8%8B%E5%BA%8F
- http://www.wenzk.com/archives/990