CentOS/Fedora网络接口配置中的PreUp,PostUp,PreDown,PostDown脚本

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]

参考资料:

Author Info :
  • From:CentOS/Fedora网络接口配置中的PreUp,PostUp,PreDown,PostDown脚本
  • URL:https://blog.ihipop.info/2011/11/2806.html
  • Please Reserve This Link,Thanks!
  • 发表评论

    您的电子邮箱地址不会被公开。 必填项已用*标注