#! /bin/bash # # network Bring up/down networking # # chkconfig: 2345 10 90 # description: Activates/Deactivates all network interfaces configured to \ # start at boot time. # ### BEGIN INIT INFO # Provides: $network ### END INIT INFO # Source function library. . /etc/init.d/functions # Network configs BRIDGE_INTERFACE=br0 BRIDGE_SLAVES="eth0 eth1" BRIDGE_IP=10.10.11.235 BRIDGE_NETMASK=255.255.255.0 BRIDGE_DEFAULT_GW=10.10.11.1 BRIDGE_STP_STATUS=on # Don't edit anything below this line RBRIDGE_SLAVES="" # Reverse list for un-loading; don't change for x in $BRIDGE_SLAVES; do RBRIDGE_SLAVES="$x $RBRIDGE_SLAVES" done cd /etc/sysconfig/network-scripts . network-functions case "$1" in start) action $"Setting network parameters: " sysctl -e -p /etc/sysctl.conf # bring up loopback interface action $"Bringing up loopback interface: " ifup ifcfg-lo for i in $BRIDGE_SLAVES do action $"Bringin down $i: " ifconfig $i down action $"Nulling $i: " ifconfig $i 0.0.0.0 done action $"Setting up bridge $BRIDGE_INTERFACE:" brctl addbr $BRIDGE_INTERFACE action $"Adjusting stp on $BRIDGE_INTERFACE: " brctl stp $BRIDGE_INTERFACE $BRIDGE_STP_STATUS for i in $BRIDGE_SLAVES do action $"Adding $i to $BRIDGE_INTERFACE: " brctl addif $BRIDGE_INTERFACE $i done # echo '1' > /proc/sys/net/ipv4/ip_forward action $"Setting up $BRIDGE_INTERFACE IP: " ifconfig $BRIDGE_INTERFACE $BRIDGE_IP netmask $BRIDGE_NETMASK up action $"Adding default gateway to route: " route add default gw $BRIDGE_DEFAULT_GW ;; stop) for i in $BRIDGE_SLAVES do action $"Deleting interface $i from $BRIDGE_INTERFACE: "brctl delif $BRIDGE_INTERFACE $i action $"Bringing down $i: " ifconfig $i down done action $"Bringing down $BRIDGE_INTERFACE: " ifconfig $BRIDGE_INTERFACE down action $"Deleting bridge $BRIDGE_INTERFACE: " brctl delbr $BRIDGE_INTERFACE # route del default gw action $"Shutting down loopback interface: " ./ifdown ifcfg-lo if [ -d /proc/sys/net/ipv4 ]; then if [ -f /proc/sys/net/ipv4/ip_forward ]; then if [ `cat /proc/sys/net/ipv4/ip_forward` != 0 ]; then action $"Disabling IPv4 packet forwarding: " sysctl -w net.ipv4.ip_forward=0 fi fi if [ -f /proc/sys/net/ipv4/ip_always_defrag ]; then if [ `cat /proc/sys/net/ipv4/ip_always_defrag` != 0 ]; then action $"Disabling IPv4 automatic defragmentation: " sysctl -w net.ipv4.ip_always_defrag=0 fi fi fi ;; *) echo $"Usage: $0 {start|stop|status}" exit 1 esac exit 0