#!/bin/bash #Copyright 2002 William Stearns #Released under the GPL #Note: This is NOT complete. You will almost certainly need to #customize it; this is provided as a starting point only. At an #absolute minimum, you need to fix the IP addresses below. #FIXME - make safe for multiple uml_switches? #Edit these: #IP address of the host as seen by the outside world HostIP=66.59.109.137 #Allocated real IP address subnet UMLRealNet=66.59.111.160 UMLRealNetMask=255.255.255.224 UMLFakeNet=172.28.0.0/16 UMLFakeNetGW=172.28.0.1 UMLFakeNetBC=172.28.255.255 UMLFakeNetMask=255.255.0.0 status () { echo "$*" } while [ -n "$1" ]; do case "$1" in [Ss][Tt][Oo][Pp]) Action='stop' ;; [Ss][Tt][Aa][Rr][Tt]) Action='start' ;; tap*) Device="$1" ;; esac shift done if [ -z "$Action" ]; then Action='start' fi case "$Action" in start) status Loading tun support modprobe tun status Setting up tap device TapDevice=`tunctl -b -u 0` HostEth='eth1' case "$TapDevice" in tap[0-9]|tap[0-9][0-9]|tap[0-9][0-9][0-9]|tap[0-9][0-9][0-9][0-9]) echo Tap device "$TapDevice" ;; *) echo Unknown tap device "$TapDevice", exiting exit ;; esac status Assigning IP addresses to tap device ifconfig "$TapDevice" $HostIP netmask 255.255.255.255 up ifconfig "$TapDevice:0" $UMLFakeNetGW netmask $UMLFakeNetMask broadcast $UMLFakeNetBC up status Setting up firewall, port forwarding, masquerading #Put any rules you need here. #iptables -A POSTROUTING -t nat -o $HostEth -s $UMLFakeNet -j MASQUERADE #For example, to forward specific ports back to one of the reserved addresses #iptables -A PREROUTING -t nat -p tcp -d $HostIP --dport 1111 -j DNAT --to 172.28.0.99:22 #iptables -A PREROUTING -t nat -p udp -d $HostIP --dport 27015 -j DNAT --to 172.28.0.2:27015 status '(re)starting uml_switch' killall -TERM uml_switch ; sleep 1 ; killall -9 uml_switch chmod 777 /tmp/uml.ctl screen -S uml_switch -t uml_switch -d -m bash -c "uml_switch -tap \"$TapDevice\" ; sleep 360000" sleep 2 chmod 777 /tmp/uml.ctl chmod 666 /dev/net/tun status Configuring IP forwarding and proxy_arp echo 1 > /proc/sys/net/ipv4/ip_forward echo 1 > /proc/sys/net/ipv4/conf/$TapDevice/proxy_arp route del -net $UMLRealNet netmask $UMLRealNetMask 2>/dev/null route add -net $UMLRealNet netmask $UMLRealNetMask dev $TapDevice status Adding routes to new address block for LastOctet in `seq 160 190` ; do arp -Ds 66.59.111.$LastOctet $HostEth pub done ;; stop) echo stop not implemented. ;; esac status 'Done!'