#!/bin/sh # bridge - This script determines the current host network settings # and reconfigures the network using a bridge # Copyright (C) 2004 Frank Sorenson (frank AT tuxrocks DOT com) # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # export IFCONFIG="/sbin/ifconfig" export ROUTE="/sbin/route -F" export BRCTL="/usr/sbin/brctl" export SLEEP="/bin/sleep 1" export HOST_IF=`route -n |egrep "^0\.0\.0\.0"|cut -c 73-` export HOST_GW=`route -n | egrep "^0\.0\.0\.0"|cut -c 17-31` export HOST_IP=`ifconfig ${HOST_IF} | grep "inet addr:" | cut -f 2 -d ":"|cut -f 1 -d " "` export HOST_BCAST=`ifconfig ${HOST_IF} | grep "Bcast:" | cut -f 3 -d ":"|cut -f 1 -d " "` export HOST_MASK=`ifconfig ${HOST_IF} | grep "Mask:" | cut -f 4 -d ":"|cut -f 1 -d " "` echo "Current config: ${HOST_IF} is ${HOST_IP}/${HOST_MASK} (bcast ${HOST_BCAST})" echo "Creating bridge" ${BRCTL} addbr bridge ${BRCTL} setfd bridge 1 ${BRCTL} sethello bridge 1 ${BRCTL} stp bridge off ${BRCTL} addif bridge ${HOST_IF} echo "Configuring IP on the bridge" ${IFCONFIG} bridge ${HOST_IP} netmask ${HOST_MASK} broadcast ${HOST_BCAST} promisc up ${SLEEP} ${IFCONFIG} bridge down ${SLEEP} ${IFCONFIG} bridge up ${SLEEP} echo "Setting ${HOST_IF} promisc" #${IFCONFIG} ${HOST_IF} down ${IFCONFIG} ${HOST_IF} 0.0.0.0 promisc up ${SLEEP} echo "Setting default gateway through bridge" ${ROUTE} add -net default gw ${HOST_GW} bridge