Created
September 14, 2013 06:06
-
-
Save mrsarm/6559224 to your computer and use it in GitHub Desktop.
VirtualBox add/remove NAT rules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# vbox-nat | |
# | |
# VirtualBox add/remove NAT rules. | |
# | |
# Author: Mariano Ruiz <mrsarm@gmail.com> | |
# | |
# License GPLv3 (2011-2013) | |
# | |
# | |
# Usefull VM commands: | |
# | |
# vboxmanage list [vms|runningvms] | |
# vboxmanage startvm "NAME" [--type headless] | |
# vboxmanage controlvm "NAME" [acpipowerbutton|poweroff|pause|resume] | |
# vboxmanage modifyvm "NAME" [--autostart-enabled [on|off]] | |
# vboxmanage modifyvm "NAME" [--autostart-delay SENCONDS] | |
# vboxmanage modifyvm "NAME" [--autostop-type disabled|savestate|poweroff|acpishutdown] | |
# vboxmanage clone "NAME" [--name CLONENAME] | |
# vboxmanage registervm "NAME" | |
# vboxmanage export "NAME" -o "NAME.ova" | |
# | |
#DEVICE="pcnet" | |
#DEVICE="pcbios" | |
DEVICE="e1000" | |
if [ -n "$3" -a "$1" = "remove" ]; then | |
LINUX_GUEST="$2" | |
NAME_SERVICE="$3" | |
vboxmanage setextradata "$LINUX_GUEST" "VBoxInternal/Devices/$DEVICE/0/LUN#0/Config/$NAME_SERVICE/Protocol" | |
vboxmanage setextradata "$LINUX_GUEST" "VBoxInternal/Devices/$DEVICE/0/LUN#0/Config/$NAME_SERVICE/GuestPort" | |
vboxmanage setextradata "$LINUX_GUEST" "VBoxInternal/Devices/$DEVICE/0/LUN#0/Config/$NAME_SERVICE/HostPort" | |
exit 0 | |
fi | |
if [ -n "$5" -a "$1" = "add" ]; then | |
LINUX_GUEST="$2" | |
GUEST_PORT="$3" | |
HOST_PORT="$4" | |
NAME_SERVICE="$5" | |
vboxmanage setextradata "$LINUX_GUEST" "VBoxInternal/Devices/$DEVICE/0/LUN#0/Config/$NAME_SERVICE/Protocol" TCP | |
vboxmanage setextradata "$LINUX_GUEST" "VBoxInternal/Devices/$DEVICE/0/LUN#0/Config/$NAME_SERVICE/GuestPort" $GUEST_PORT | |
vboxmanage setextradata "$LINUX_GUEST" "VBoxInternal/Devices/$DEVICE/0/LUN#0/Config/$NAME_SERVICE/HostPort" $HOST_PORT | |
exit 0 | |
fi | |
echo "Use: $0 {remove LINUX_GUEST NAME_SERVICE | add LINUX_GUEST GUEST_PORT HOST_PORT NAME_SERVICE}" | |
exit 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment