#!/bin/bash # Name: tapctrl # Usage: tapctrl start|stop # Provides: tap for virtualbox over external network including wireless # Short-Description: set up tap device for sharing wifi interface with vbox # Description: create a virtual tap interface, give it an IP address, set up iptables to masquerade through the default # device and set up proxy arp with parprouted daemon to enable correct routing # Author: Jack Knight - Open Source Migrations Ltd, UK (http://www.osml.co.uk) ############################## # Set up variables here: DESC="Virtualbox IP tap" PATH=/sbin:/bin:/usr/sbin:/usr/bin TUNDEVICE=tap1 # Arbitrary, but must match device used in virtualbox network device setting LANDEVICE=eth1 # Adjust to match your network device - may be eth0, eth1 ath0, wlan1 etc. IPADDR=172.16.254.254 # arbitrary, but make sure you pick something from an unused subnet case "$1" in start|restart|force-reload) echo -n "Starting $DESC: " tunctl -t $TUNDEVICE -u $USER ip link set $TUNDEVICE up ip addr add $IPADDR dev $TUNDEVICE arp -Ds $IPADDR $TUNDEVICE pub iptables -t nat -A POSTROUTING -o $LANDEVICE -j MASQUERADE iptables -t nat -P POSTROUTING ACCEPT # allow other if's to work echo 1 > /proc/sys/net/ipv4/ip_forward echo 1 > /proc/sys/net/ipv4/conf/$TUNDEVICE/proxy_arp parprouted $LANDEVICE $TUNDEVICE stop) echo -n "Stopping $DESC: " iptables --table nat -F killall parprouted ip link set $TUNDEVICE down ;; *) N=/etc/init.d/$NAME echo "Usage: $N start|stop" >&2 exit 1 ;; esac exit 0