57 lines
1.1 KiB
Bash
Executable file
57 lines
1.1 KiB
Bash
Executable file
#!/bin/sh
|
|
#
|
|
# this is the qemu-ifup script that should be run at qemu's boot
|
|
#
|
|
# maybe you have to include this script in your /etc/sudoers file because it has to run as root
|
|
#
|
|
|
|
# determine the interface to the outside
|
|
IF_WORLD=`/sbin/route -n | grep " UG " | sed "s/ */ /g" | cut -d " " -f 8 | head -1`
|
|
# nothing found? - sorry!
|
|
[ -z "$IF_WORLD" ] && IF_WORLD=eth0
|
|
|
|
|
|
if [ "$UID" -ne 0 ]
|
|
then sudo $0 $*
|
|
exit 0
|
|
fi
|
|
|
|
echo "Laufe als root ..."
|
|
|
|
IPT=/sbin/iptables
|
|
[ ! -x $IPT ] && IPT=/usr/sbin/iptables
|
|
|
|
IPT_RULES=" FORWARD -i tun0 -o $IF_WORLD -j ACCEPT
|
|
FORWARD -i $IF_WORLD -o tun0 -m state --state ESTABLISHED,RELATED -j ACCEPT
|
|
POSTROUTING -t nat -o $IF_WORLD -j MASQUERADE
|
|
INPUT -i tun0 -j ACCEPT
|
|
OUTPUT -o tun0 -j ACCEPT"
|
|
|
|
aktiviere_forward()
|
|
{
|
|
echo "$IPT_RULES" | while read a
|
|
do $IPT -A $a
|
|
done
|
|
echo 1 >/proc/sys/net/ipv4/ip_forward
|
|
}
|
|
|
|
deaktiviere_forward()
|
|
{
|
|
echo "$IPT_RULES" | while read a
|
|
do $IPT -D $a
|
|
done
|
|
echo 0 >/proc/sys/net/ipv4/ip_forward
|
|
}
|
|
|
|
case "$1" in
|
|
stop )
|
|
deaktiviere_forward
|
|
#/etc/init.d/dhcp stop
|
|
;;
|
|
* )
|
|
/sbin/ifconfig $1 192.168.0.1
|
|
#/etc/init.d/dhcp start
|
|
aktiviere_forward
|
|
;;
|
|
esac
|
|
|