1 #!/bin/sh 2 # Usage: uml-net ( --start <username> | --stop ) 3 4 # Copyright (C) 2010, 2011, 2013 Paul Boddie <paul@boddie.org.uk> 5 # 6 # This program is free software; you can redistribute it and/or modify it under 7 # the terms of the GNU General Public License as published by the Free Software 8 # Foundation; either version 3 of the License, or (at your option) any later 9 # version. 10 # 11 # This program is distributed in the hope that it will be useful, but WITHOUT 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 # details. 15 # 16 # You should have received a copy of the GNU General Public License along with 17 # this program. If not, see <http://www.gnu.org/licenses/>. 18 19 # Configuration: 20 if [ -e userinstall-defaults-uml ]; then 21 . "$PWD/userinstall-defaults-uml" 22 elif [ -e /etc/default/userinstall-uml ]; then 23 . /etc/default/userinstall-uml 24 else 25 echo "No defaults found for userinstall (UML)." 1>&2 26 exit 1 27 fi 28 29 PROGNAME=`basename "$0"` 30 31 if [ "$1" = "--start" ]; then 32 chgrp adm /dev/net/tun 33 tunctl -u "$2" -t "$TUNDEVICE" 34 ifconfig "$TUNDEVICE" "$HOSTADDRESS" up 35 bash -c "echo 1 > /proc/sys/net/ipv4/ip_forward" 36 iptables -t nat -I POSTROUTING -o "$NETDEVICE" -j MASQUERADE 37 iptables -I FORWARD -i "$TUNDEVICE" -j ACCEPT 38 iptables -I FORWARD -o "$TUNDEVICE" -j ACCEPT 39 40 elif [ "$1" = "--stop" ]; then 41 iptables -t nat -D POSTROUTING 1 42 iptables -D FORWARD 1 43 iptables -D FORWARD 1 44 tunctl -d "$TUNDEVICE" 45 else 46 echo "Usage: $PROGNAME --start <username> | --stop" 1>&2 47 exit 1 48 fi