home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / doc / ifupdown / examples / bridge next >
Encoding:
Text File  |  2005-05-12  |  2.0 KB  |  70 lines

  1. #!/bin/sh 
  2. # The following script example, if dropped in /etc/network/if-pre-up.d/
  3. # and under /etc/network/if-down.d/, will manage to configure a bridge 
  4. # if defined in the /etc/network/interfaces file as either:
  5. #
  6. # Note: The bridge-utils package already provide a similar (more
  7. # powerful) script this is just provided here for convenience and to
  8. # show how the /etc/network/if-*.d/ methods can be defined.
  9. # [ a bridge with an associated IP address ]
  10. #  iface br0 inet static
  11. #       bridge-ifaces eth0 eth1
  12. #       address 192.168.1.1
  13. #       netmask 255.255.255.0
  14. # [ a bridge which acts as an anonymous bridge ]
  15. #  iface br0 inet manual
  16. #       bridge-ifaces eth0 eth1
  17. #       up ifconfig $IFACE up
  18. #
  19. # For more information read:
  20. #  http://bridge.sourceforge.net/howto.html
  21.  
  22. brctl=`which brctl`
  23.  
  24. # Notice that the bridge-utils package must be installed and 
  25. # we need to have the BRIDGE_IFACES in order to work
  26. [ "$IF_BRIDGE_IFACES" = "" ] && exit 0
  27. if [ -z "$brctl" ] ; then
  28.     # ? Somebody is trying to use us without having bridge-utils?
  29.     echo "Cannot find the 'brctl' program to setup the bridge"
  30.     echo "Hint: Have you installed the bridge-utils package?"
  31.     exit 1
  32. fi 
  33.  
  34. # Check all interfaces before proceeding
  35. for i in $IF_BRIDGE_IFACES; do
  36.     ip link show $i >/dev/null 2>&1
  37.     if [ $? -ne 0 ] ; then
  38.         echo "Interface $i is not available, aborting"
  39.         exit 1
  40.     fi
  41. done
  42.  
  43. if [ "$MODE" = "start" ] ; then
  44.     # We are being called by ifup:
  45.     # Bring up all the bridge interfaces
  46.     for i in $IF_BRIDGE_IFACES; do
  47.         ifconfig $i 0.0.0.0 up
  48.     done
  49.     # And now add the bridge itself and the interfaces which are part
  50.     # of the bridge
  51.     brctl addbr $IFACE
  52.     for i in $IF_BRIDGE_IFACES; do
  53.         brctl addif $IFACE $i
  54.     done
  55. elif [ "$MODE" = "stop" ];  then
  56.     # We are being called by ifdown:
  57.     # Remove the bridge itself and the bridge association
  58.     for i in $IF_BRIDGE_IFACES; do
  59.         brctl delif $IFACE $i
  60.     done
  61.     brctl delbr $IFACE
  62.     # Bring down all the bridge interfaces
  63.     for i in $IF_BRIDGE_IFACES; do
  64.         ifconfig $i down
  65.     done
  66. fi
  67.  
  68. exit 0
  69.