Setting up a bridge server

Theos's picture
Submitted by Theos on Fri, 2006-04-14 12:04. ::
Place this script in /etc/rc.d/init.d Usage: service bridge start
#!/bin/bash
PATH="/sbin:/bin:/usr/sbin:/usr/local/sbin";
IPADRESSE="192.168.1.163";
BROADCAST="192.168.1.255";
NETMASK="255.255.255.0";
BRIDGENAME="mybridge";

cmd="$1";
[ -z "$cmd" ] && cmd="start";
case "$cmd" in
  start)
    brctl addbr $BRIDGENAME;
    brctl stp $BRIDGENAME on;
    brctl addif $BRIDGENAME eth0;
    brctl addif $BRIDGENAME eth1;
    (ifdown eth0 1>/dev/null 2>&1;);
    (ifdown eth1 1>/dev/null 2>&1;);
    ifconfig eth0 0.0.0.0 up;
    ifconfig eth1 0.0.0.0 up;
    ifconfig $BRIDGENAME $IPADRESSE broadcast $BROADCAST netmask $NETMASK up ### Adapt to your needs.
    route add default gw $IPADRESSE; ### Adapt to your needs.
    for file in $BRIDGENAME eth0 eth1;
    do
      echo "1" > /proc/sys/net/ipv4/conf/${file}/proxy_arp;
      echo "1" > /proc/sys/net/ipv4/conf/${file}/forwarding;
    done;
    echo "1" > /proc/sys/net/ipv4/ip_forward;
    service network restart;
    touch /var/run/bridge.pid;
    ;;
  stop)
    echo -n $"Shutting down bridge: "
    brctl delif $BRIDGENAME eth0;
    brctl delif $BRIDGENAME eth1;
    ifconfig $BRIDGENAME down;
    brctl delbr $BRIDGENAME;
    rm -f /var/run/bridge.pid;
    #ifup eth0; ### Adapt to your needs.
    #ifup eth1; ### Adapt to your needs.
    ;;
status)
   if [ -f /var/run/bridge.pid ]; then
       echo -n $"bridge is running  ";
   else
       echo -n $"bridge is stopped ";
  fi
    ;;
  restart,reload)
    $0 stop;
    sleep 3;
    $0 start;
    ;;
 restart)
    $0 stop
    $0 start
    ;;
 *)
    echo $"Usage: bridge {start|stop|status|restart}"
    exit 1
esac;
ichihi
Submitted by ichihi on Fri, 2006-04-21 14:17.

That will turn my computer into a very-expensive 2-port Ethernet bridge :)

-Imed