| Revision 57 (by dpavlin, 2008/01/10 20:11:42) |
setup bridge between eth0 and wifi or other way around
|
#!/bin/sh
wif=`iwconfig 2>&1 | grep -i 802.11 | cut -d" " -f1`
essid=foobar
key=s:secret
ap=1
# doma
essid=dreamhouse
key=off
ap=0
test -z "$wif" && (
sudo rmmod ath_pci
sudo modprobe ath_pci
wif=`iwconfig 2>&1 | grep -i 802.11 | cut -d" " -f1`
test -z "$wif" && echo "no wifi device" && exit
)
echo "*** stop interfaces $wif eth0"
sudo ifconfig $wif down
sudo ifconfig eth0 down
sudo ifconfig br0 down
sudo brctl delif br0 $wif
sudo brctl delif br0 eth0
sudo brctl delbr br0
if [ $ap == 1 ] ; then
mode=ap
else
mode=managed
fi
echo "*** setup wifi $mode $essid"
sudo wlanconfig $wif destroy || exit
sudo wlanconfig $wif create wlandev wifi0 wlanmode $mode || exit
wif=`iwconfig 2>&1 | grep -i 802.11 | cut -d" " -f1`
test -z "$wif" && echo "no wifi device" && exit
echo "*** using wifi $wif $essid"
sudo iwconfig $wif essid $essid
sudo iwconfig $wif key $key
sudo ifconfig $wif up
sudo iwconfig $wif
echo "*** creating bridge $wif eth0"
sudo brctl addbr br0
sudo brctl delif br0 eth0
sudo brctl delif br0 $wif
sudo ifconfig eth0 0.0.0.0 up
sudo brctl addif br0 eth0
sudo brctl addif br0 $wif
echo "*** getting public IP address"
sudo dhclient br0
sudo ln -sf /etc/resolv.conf.dhclient-new /etc/resolv.conf-upstream
sudo /etc/init.d/dnsmasq restart