In the previous VirtualBox post, IÂ explainedÂ how (and how not) to set up bridged networking with LAN access to a Virtual Machine running on a Windows XP Host. Today I will explain how to do the same thing (without the How Not To part) using a virtual Machine running on a Headless Ubuntu Server.
For this example we can assume a few things:
- You have already set up a headless VirtualBox server
- You have already created a Virtual Machine instance. For this sample, we will call the Virtual Machine “MyVM”.
Believe it or not, setting up bridged networking to allow your VM to access your network is pretty simple and completed by issuing the following VBoxManageÂ command in a terminal window.
Command: VBoxManage modifyvm “MyVM” –nic1 bridged –nictype1 82540OEM –bridgeadapter1 eth0
Break it down
To understand a bit more about what’s happening here, let’s break down the command string from the beginning.
VBoxManage – This is the command line utility used to access, control, configure and manage your VirtualBox Virtual Machines.
modifyvm – This command allows you to make changes to the properties of a Virtual Machine, including the amount of memory assigned, nic interfaces, Virtual device boot sequence, number of CPUs, etc. It can be compared to the Settings dialog of the VirtualBox Graphical user Interface. The command line version, however, offers additional advanced options not found in the GUI.
Note: the VM must be registered within VirtualBox, but must not be running
“MyVM” – This is simply the name of the VM you want to modify.
–nic1 bridged – The –nic1 parameter is used to set the type of networking your VM should useÂ for each of the it’s virtual network cards. You can have more than one network card in use for a VM so the paramater is written as –nicX where X is the network card being targeted. Here, “–nic1” is the first network interface, –nic2 would be the second and so on. This portion of the command string is setting the type of networking on the first interface to “bridged”.
–nictype1 82540OEM – The –nictype1 parameter allows you to specify which networking hardware VirtualBox should emulate for the VM’s virtual network cards. Here we set the networking hardware to emulate an Intel PRO/1000 MT Desktop card or 82540EM.
–nictypeX follows the same sequence numbering and –nicX for multiple interfaces where –nictype1 is the first virtual card, –nictype2 is the second and so on.
Note: Â The following is a list of the available nic hardware types and the associated ID recognized in VirtualBox.
- AMD PCNet PCI II =Â Am79C970A
- AMD PCNet FAST III =Â Am79C973Â (the default)
- Intel PRO/1000 MT Desktop =Â 82540EM
- Intel PRO/1000 T Server =Â 82543GC
- Intel PRO/1000 MT Server =Â 82545EM
- Paravirtualized network adapter =Â virtio-net
–bridgeadapter1 eth0 – Finally we have the –bridgeadapter paramater. This is the only part of the command string that references a part of the VirtualBox host and tells your VM which physical host adapter to pass it’s traffic through.
Again, this uses the same sequence numbering as nicX and nictypeX for multiple interfaces. Here, we are setting the bridgeadapter for our first virtual network card to use the eth0 Â interface on the host. Note that is eth zero, as in the number and not the letter O.
And that’s it. Restart your VM and you should now have a working bridged network interface for you VM with full network and internet access.
4 Replies to “VirtualBox and Bridged Networking on a Headless Ubuntu Server Host”
I know that your post is more than a year old. However, I’d like to ask what command should I use to add another NIC in virtual box. I wanted to have more than 4 NIC.
@Van Leo Adrivan
You would use the same or similar commands I wrote about above.
VBoxManage modifyvm â€œMyVMâ€ â€“nic1 bridged â€“nictype1 82540OEM â€“bridgeadapter eth0
” switch is how you create new adapters. Adapter 1 is created with –nic1, adapter 2 is created with –nic2 and so on. Then you specify the type of networking and the nic type for each one. You could also bridge the virtual adapter through different physical adapters (eth0, eth1, eth2, etc)) if you have more than one physical adapter in the host.
I dont understand, when i execute : sudo VBoxManage modifyvm “myVM” –nic1 bridged –nictype “virtio-net” –bridgeadapter eth0
I receive the error : VBoxManage: error: –nictype: RTGetOpt: Command line option needs an index.
I just want to see my VM in my local network, with sharing folder like : \\myVM\shared_folder
Thanks for your help
Thanks for commenting Magister. It looks to me that you didn’t provide an index to the nictype. –nictype needs an index similar to –nictype[x] where x is the adapter index. Since you used –nic1, I assume 1 is the index for the adapter so you also need to use the same index for nictype. Try using –nictype1. Note the added index of 1 to the end.
You’ll also need to add the index to the –bridgeadapter as well. –bridgeadapter1
Comments are closed.