#!/bin/sh # # network Bring up/down networking # # chkconfig: 2345 10 90 # description: Activates/Deactivates all network interfaces configured to \ # start at boot time. # probe: true # $Id: network,v 1.22 1999/09/15 10:35:07 misiek Exp $ # NLS NLS_DOMAIN="rc-scripts" # Source function library. . /etc/rc.d/init.d/functions . /etc/rc.d/init.d/functions.network [ ! -f /etc/sysconfig/network ] && exit 0 . /etc/sysconfig/network # Check that networking is up. [ "${NETWORKING}" == "no" -o "${NETWORKING}" == "" ] && exit 0 [ -x /sbin/ip ] || exit 0 ###### # initialize networking: # - check IPv4, IPv6, IPX can be handled by system # - setup default IPv{4,6} interfaces policy like: # - forwarding, # - spoofig protection, # - icmp echo ignore broadcasts, # - setup lo interface network_init() { # Set UP loopback interface set_up_loopback # Modprobe needed devices modprobe_net # Spoofing protection ipv4_anti_spoofing on # IPv4 forwarding proc_net ipv4/ip_forward start 1 0 IPV4_FORWARDING "IPv4 forwarding" # IPv6 forwarding proc_net ipv6/conf/all/forwarding start 1 0 IPV6_FORWARDING "IPv6 forwarding" # Setup NAT rules setup_nat on } network_postinit() { # Set static ARP table static_arp } ###### # deinitialize networking # - down lo interface. network_deinit() { # Set down NAT rules setup_nat off # IPv6 forwarding proc_net ipv6/conf/all/forwarding stop 1 0 IPV6_FORWARDING "IPv6 forwarding" # IPv4 forwarding proc_net ipv4/ip_forward stop 1 0 IPV4_FORWARDING "IPv4 forwarding" # Spoofing protection ipv4_anti_spoofing off # Set DOWN loopback interface set_down_loopback } # find all the interfaces besides loopback. # ignore aliases, alternative configurations, and editor backup files interfaces="`(cd /etc/sysconfig/interfaces && ls ifcfg* | \ egrep -v '(ifcfg-lo|:)' | egrep 'ifcfg-[a-z0-9]+$' | sed 's/^ifcfg-//g' | xargs) 2> /dev/null`" interfaces_boot="`(cd /etc/sysconfig/interfaces && ls ifcfg* | \ egrep -v '(ifcfg-lo|ifcfg-sit|:)' | egrep 'ifcfg-[a-z0-9]+$' | \ xargs egrep -l "ONBOOT=[^n][^o]" | sed 's/^ifcfg-//g') 2> /dev/null`" interfaces_sit_boot="`(cd /etc/sysconfig/interfaces && ls ifcfg-sit* | \ egrep 'ifcfg-[a-z0-9]+$' | xargs egrep -l "ONBOOT=[^n][^o]" | sed 's/^ifcfg-//g') 2> /dev/null`" tunnels="`(cd /etc/sysconfig/interfaces && ls -1 tnlcfg-* | \ xargs egrep -l "ONBOOT=[^n][^o]" | sed 's/^tnlcfg-//g') 2> /dev/null`" # See how we were called. case "$1" in start) network_init for i in $interfaces_boot $interfaces_sit_boot; do /sbin/ifup $i boot done for i in $tunnels; do /sbin/tnlup $i boot /sbin/ifup tnlcfg-$i boot done network_postinit touch /var/lock/subsys/network ;; stop) for i in $tunnels; do /sbin/ifdown tnlcfg-$i boot /sbin/tnldown $i boot done for i in $interfaces_sit_boot $interfaces_boot; do /sbin/ifdown $i boot done network_deinit rm -f /var/lock/subsys/network ;; status) nls "Configured devices:" echo "lo $interfaces" nls "Configured tunnels:" echo "$tunnels" nls "Currently active devices and tunnels:" /sbin/ip link show | egrep '^[^ ].*' |sed 's/[0-9]*: \(.*\):.*/\1/'|xargs ;; restart) $0 stop $0 start ;; *) echo "Usage: $0 {start|stop|restart|status}" exit 1 esac exit 0