Script for opening ports for virtual machines (Virtualbox)

I’m working on a Linux Mint based VM which will include everything needed to get up on the hypergrid quickly. I’m working on the assumption that you can have your router forward ports to your PC, and then have the PC forward those ports to your VM.

In order to get that to work, a range of ports needs to be open on the VM. I adapted the information I gleaned from this page into a shell script, and I’m leaving it here for future reference, and in hopes it helps someone else.

It’s four series of loops; the first opens tcp ports 8000 to 8005, the second loop opens udp ports 8000 to 8005, the third opens tcp ports 9000 to 9010, the fourth and final loop opens udp ports 9000 to 9010.

Enjoy!

PS, quick note:

This script depends on bash, which usually lives under /bin, but may be in a different place on  your system.

====copy and paste below this line===
#!/bin/bash
#uncomment and set this to the actual name of your machine! Remember to put a “\” in front of any spaces or other whitespaces.
#export VMNAME1=MY\ SHARONA

#for Robust
for i in {8000..8005}; do

echo VBoxManage modifyvm “$VMNAME1” –natpf1 “robust_tcp$i,tcp,,$i,,$i”;
VBoxManage modifyvm “$VMNAME1” –natpf1 “robust_tcp$i,tcp,,$i,,$i”;

echo VBoxManage modifyvm “$VMNAME1” –natpf1 “robust_udp$i,udp,,$i,,$i”;
VBoxManage modifyvm “$VMNAME1” –natpf1 “robust_udp$i,udp,,$i,,$i”;

done

#for Opensim

#open ten ports, probably 8 more than is needed.
for i in {9000..9010}; do

echo VBoxManage modifyvm “$VMNAME1” –natpf1 “opensim_tcp$i,tcp,,$i,,$i”;
VBoxManage modifyvm “$VMNAME1” –natpf1 “opensim_tcp$i,tcp,,$i,,$i”;

echo VBoxManage modifyvm “$VMNAME1” –natpf1 “opensim_udp$i,udp,,$i,,$i”;
VBoxManage modifyvm “$VMNAME1” –natpf1 “opensim_udp$i,udp,,$i,,$i”;

done
====copy and paste above this line=====

Advertisements

About hanheld

I'm a virtual world resident; I build, I organise, blog and play with server software (so far whitecore sim and opensim).
This entry was posted in Uncategorized and tagged , , , . Bookmark the permalink.