Virtualbox bridged networking CLI Example

  |   Source

Introduction

In this article we will see how to create a virtualbox vm using command line and use bridged networking. I am using slax 64 bit live iso for this example

Creating the virtual machine

Download slax iso

mkdir  /tmp/vmtest 
cd /tmp/vmtest 
wget http://ftp.linux.cz/pub/linux/slax/Slax-7.x/7.0.8/slax-English-US-7.0.8-x86_64.iso

Create the bridge interface in host os

brctl addbr vmtestbr1 
ifconfig  vmtestbr1 192.168.222.1  netmask 255.255.255.0 up 
ping -c 2 192.168.222.1

Create the VM using vboxmanage

# Register the VM 
VBoxManage createvm --name "vmtest" --register 
# Configure VM settings  
VBoxManage modifyvm vmtest --ostype  "Linux26_64" --memory 4096 --acpi on --cpus 1  --description "VM Test"
# Declare a bridge interface 
VBoxManage modifyvm vmtest --nic1 bridged --nictype1 82545EM --bridgeadapter1 vmtestbr1
# VRDE is for access via rdp client
VBoxManage modifyvm vmtest --vrde on 
# Create an HDD 
VBoxManage createhd --filename /tmp/vmtest/vmtest.vdi --size 10000
# Add an HDD Controller 
VBoxManage storagectl vmtest --name "IDE Controller" --add ide
# Map the HDD and ISO via IDE Controller
VBoxManage storageattach vmtest --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium  /tmp/vmtest/vmtest.vdi 
VBoxManage storageattach vmtest --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium /tmp/vmtest/slax-English-US-7.0.8-x86_64.iso
# Boot from DVD 
VBoxManage modifyvm vmtest --boot1 dvd

Start the VM

# for a remote vm use headless to access the vm via rdp 
vboxmanage startvm vmtest --headless
## for a local vm  access via GUI 
# vboxmanage startvm vmtest

Ping from guest to host

A remote desktop client like Remina ( Ubuntu ) can be used to access the vm desktop. On VM desktop open a console and verify bridge networking.

ifconfig -a  
# interface name may be different 
ifconfig eth0 192.168.222.2 netmask 255.255.255.0
ping -c 4  192.168.222.1

Stop and remove the vm

Stop and Remove the VM

# this will power-off the vm 
vboxmanage controlvm vmtest poweroff  
# this deletes the vm 
vboxmanage unregistervm vmtest --delete

Remove the bridge interface

ifconfig vmtestbr1 0.0.0.0 down 
brctl delbr vmtestbr1
Comments powered by Disqus
Share