VirtualBox forward ports below 1024

The VirtualBox online-manual writes “Forwarding host ports < 1024 impossible…”. This tutorial shows that it is still possible. I know that there are several reasons not to do so, but there are also reasons where it is necessary.

Conditions

  • VirtualBox with VM configured (not running)
  • You know the root password

Example for Ubuntu

# become root
$ sudo su -

# start VirtualBox Manager
$ virtualbox

Now you probably need to import the VM. Attention! The acces rights will be changed!

Port Forwarding

Configure or just check the port forwarding. To do so, you can use the graphical port forwarding editor or even the command line (VBoxManage).

VirtualBox port forwarding editor

At the end you can start the VM as root.

Create Windows 10 Vagrant Base Box

In the first part I have shown how to create the Windows 10 VirtualBox VM. This time I will show you how to create a Vagrant Base Box.

Preconditions

Important Windows 10 Settings

Turn off and disable UAC (here you will find different ways)

disable windows 10 uac

Enable Remote Desktop

remote desktop settings

Configure WinRM on Windows

open the Command Prompt as Admin

> winrm quickconfig -q
> winrm set winrm/config/winrs @{MaxMemoryPerShellMB="300"}
> winrm set winrm/config @{MaxTimeoutms="1800000"}
> winrm set winrm/config/service @{AllowUnencrypted="true"}
> winrm set winrm/config/service/auth @{Basic="true"}
> sc config WinRM start=auto

Optional Settings for Windows

open the PowerShell as Admin

# remove all of the metro apps
> Get-AppXPackage -AllUsers | Remove-AppXPackage

# remove log files
> Get-Childitem "C:\Windows\Logs\dosvc" | Remove-Item -Verbose

# disables the system restore feature
> Disable-ComputerRestore c:

# disable hibernation
> powercfg -h off

# allow Powershell scripts to provision
> Set-ExecutionPolicy -ExecutionPolicy Unrestricted

Okay,… that is all. Now shutdown windows…

Create Vagrant BaseBox

# goto default directory
$ cd VirtualBox\ VMs/

# create base box from VM
$ vagrant package --base Win10x64 --output Win10x64.box

# add box
$ vagrant box add lupin/windows10 Win10x64.box

# check vagrant boxes
$ vagrant box list

Create and run test project

# create project folder
$ mkdir ~/test_project && cd ~/test_project

# initializes to be a Vagrant environment
$ vagrant init lupin/windows10

# edit Vagrantfile
$ vim Vagrantfile

# start VM
$ vagrant up

# start rdp client
$ vagrant rdp
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|

  config.vm.box = "lupin/windows10"
  config.vm.guest = :windows
  config.vm.communicator = "winrm"
  config.winrm.username = "vagrant"
  config.winrm.password = "vagrant"
  config.vm.boot_timeout = 600
  config.vm.network :forwarded_port, guest: 3389, host: 3389
  config.vm.network :forwarded_port, guest: 5985, host: 5985, id: "winrm", auto_correct: true

  config.vm.provider "virtualbox" do |vb|
    # vb.gui = true
    vb.memory = "2048"
    vb.cpus = 2
    vb.name = "Windows_Vagrant"
  end

end

Values for username and password should match your needs!

Create Windows 10 VirtualBox VM

This tutorial is designed to prepare for another!

Preconditions

Prepare VM

# switch into default VirtualBox directory
$ cd VirtualBox\ VMs/

# create new VirtualBox VM
$ VBoxManage createvm --name "Win10x64" --ostype Windows10_64 --register

# configure system settings of VM
$ VBoxManage modifyvm "Win10x64" --memory 2048 --cpus 2 --acpi on --pae on --hwvirtex on --nestedpaging on

# configure boot settings of VM
$ VBoxManage modifyvm "Win10x64" --boot1 dvd --boot2 disk --boot3 none --boot4 none

# configure video settings
$ VBoxManage modifyvm "Win10x64" --vram 128 --accelerate3d on

# configure audio settings
$ VBoxManage modifyvm "Win10x64" --audio coreaudio --audiocontroller hda

# configure network settings
$ VBoxManage modifyvm "Win10x64" --nic1 nat

# configure usb settings
$ VBoxManage modifyvm "Win10x64" --usb on

# create storage medium for VM
$ VBoxManage createhd --filename ./Win10x64/Win10x64.vdi --size 30000

# modify a storage controller
$ VBoxManage storagectl "Win10x64" --name "SATA" --add sata

# attache storage medium to VM
$ VBoxManage storageattach "Win10x64" --storagectl "SATA" --port 0 --device 0 --type hdd --medium ./Win10x64/Win10x64.vdi

# add windows iso
$ VBoxManage storageattach "Win10x64" --storagectl "SATA" --port 1 --device 0 --type dvddrive --medium /path/to/windows.iso

# add guest addition iso
$ VBoxManage storageattach "Win10x64" --storagectl "SATA" --port 2 --device 0 --type dvddrive --medium /path/to/VBoxGuestAdditions.iso

# start VM
$ VBoxManage startvm Win10x64

You can now begin the installation. Do not forget the Guest Additions! After successful installation and configuration, you can remove the unnecessary media.

# remove media (on stopped VM)
$ VBoxManage storageattach "Win10x64" --storagectl "SATA" --port 1 --device 0 --type dvddrive --medium none
$ VBoxManage storageattach "Win10x64" --storagectl "SATA" --port 2 --device 0 --type dvddrive --medium none