Setting up a local network between the computer and the virtualbox virtual machine. Setting up a network on the Oracle VM VirtualBox virtualization platform Connect to a virtual machine over the network

05/23/2017 Romchik

Good day. In one of the articles, we installed Ubuntu as a guest system and gave it access to the Internet. We didn't have any problems. But I would like to have access to the guest Ubuntu system from the host, while our Ubuntu remains behind NAT. There are several options for implementing this task. And I will look at one - creating another network interface. The second option, I will not consider port forwarding, because. he didn't fit me. Let's get started.

We need to add another virtual adapter (one already exists and is used to access the Internet of guest OSes)

To do this, open the VirtualBox settings

You can also configure a DHCP server.

Click "OK". Now let's move on to setting up the virtual machine.

Setting up a network in a virtual machine.

Open the settings of our virtual machine.

Select "Network" and go to the "Adapter 2" tab

Turn on the network adapter. Then select the connection type "Virtual adapter" and select a name from the list. Click "OK"

This completes the configuration of the virtual machine. We start the car.

Ubuntu guest setup

Open a terminal and enter the ifconfig command.

And so, the enp0s3 interface is used to access the Internet, and enp0s8 is used to connect the guest system to the host. Ok, let's write enp0s8 a static IP. For example, 10.0.1.10.

Open sudo gedit /etc/network/interfaces

And add:

Auto enp0s8 iface enp0s8 inet static address 10.0.1.10 netmask 255.255.255.0

Save and restart the network with the command:

sudo /etc/init.d/networking restart

We are waiting and checking, we will start ping on 8.8.8.8

Everything works great. Now let's check the access from the host to the guest system. We start ping on 10.0.1.10

That's all.

Conclusion.

We have configured access to the guest system from the host, while there is access from the guest system to the Internet (via NAT)

In order not to miss the release of new articles, we subscribe.

VirtualBox virtual machines are very often used to test various software and its interaction with each other. Usually, such programs need access to the Internet. From time to time, it becomes necessary to test the operation of programs over the network or even create a small test lab from virtual machines.

In this tutorial, we will look at how VirtualBox networking is configured in various ways. You will learn how to combine machines into one local network, how to give them access to the Internet and how to connect them to the main system. But first, let's talk about how a network can work.

There are several ways to set up networking in virtualbox, and each of them is better for one task and less for another. Consider the main ones:

  • NAT- This method is used by default. For each machine, a separate internal local network is created, in which the machine receives ip 10.10.0.1. The machine can connect to the internet using NAT technology, and you can access the machine using VirtualBox port forwarding, but if you have two virtual machines, you won't be able to communicate between them like that. And if you can access the guest system from the main system, then you won’t be able to access the main or guest system;
  • Virtual host adapter- a virtual network adapter is created, to which several virtual machines can be connected, thereby uniting them into a local network. There is no access to the Internet, but the machines are on the same network and each has its own ip address, now they can interact with each other. The main system is also available via ip 192.168.56.1. Machines are accessible not only among themselves, but also from the main system;
  • network bridge- with this connection, the virtual machine becomes a full member local network to which the main system is connected. The machine uses the network interface to get the address from the router and becomes available to other devices, just like the main computer by its ip address.
  • Internal network- almost the same as the virtual host adapter, only without the ability to access the virtual network from the main system, there is no access to the Internet.
  • Universal Driver- allows you to use the driver from the VirtualBox extensions to communicate between machines located on different physical hosts.

Now let's look at each setting option in more detail.

Setting up the Virtualbox network

1. NAT network setup

There is almost nothing to talk about here. Gaining access to the network through NAT is enabled by default. I discussed port forwarding in a separate article. But if you previously disabled network adapters, then to enable NAT back, just open the settings of the desired machine:

Go to tab "Net":

Choose one of the adapters. Multiple adapters can be connected to a virtual machine, which is very convenient, since you can combine a virtual host adapter and NAT together to get the benefits of both modes. Next, you need to select "NAT" on the list "Connection type".

On the tab "Additionally" you can configure the adapter device brand and MAC address:

If you are going to install there on Windows, then Intel PRO / 1000 MT Desktop will work better, and for Linux, you can leave AMD PCNet FAST III, since it is supported by all operating systems.

2. NAT network setup

Support for NAT networks has been added in Virtualbox since 4.3, this works very similar to a virtual host adapter, all machines connected to the same network can access each other, and Internet access is done through NAT, but the main system for accessing guest does not have. To set up such a connection, you must first create a NAT network. To do this, open "File" -> "Settings","Net". Here go to the tab "NAT networks". Next, click the green plus button to create a new network:

Click "OK" and close this window. Next, open the settings for the virtual machine, go to the tab "Net" -> "Adapter 1":

Select "Connection type" - "Network NAT", a "Name"- newly created network.

Now all machines connected to this network will be available to each other, just like in VMWare.

3. Configuring the virtual host adapter

Now the task is a little more interesting - we need a virtualbox local network between several virtual machines and a host. In order for all this to work on Linux, we need the vboxnetadp and vboxnetflt kernel modules to be loaded:

lsmod | grep vbox

You may need to install the net-tools package for them to work properly. Next, you need to create the virtual adapter itself. To do this, open the menu "File", then "Settings" -> "Net". Then press the green plus button and then "OK", all parameters can be left as default. In VirtualBox 5.2 and above, the interface has been changed. Now you need to open the menu "Tools" -> "Host Network Manager":

Click the button "Create", then, in the adapter that appears, next to the DHCP item, check the box "Included".

Now go back to the list of virtual machines, go to machine settings, "Net":

Select "Connection type" - "Virtual Host Adapter", and the name is vboxnet0, the one you created earlier.

For all machines that you want to network together, you must select the same host adapter. If you want to add Internet access to machines as well, just go to the tab "Adapter 2", enable it and configure NAT as described in the first paragraph.

4. Configuring the VirtualBox Network Bridge

The network bridge mode allows the virtual machine to act as a real network device with a separate ip address. To configure this, open the same menu - virtual machine settings, then "Net". Select here "Connection type" - "Network Bridge":

In field "Name" you need to select the network interface that will be used to communicate with the outside world. The disadvantage of this method is that external computers will be able to access the virtual machine, and this is not very good from a security point of view.

5. VirtualBox internal network

Virtualbox internal network mode is similar to "Virtual Host Adapter", with the only exception that there will be no access to the guest system from the host system, and everything is a little easier to set up. Enough to choose "Connection type" -"internal network" and then just choose desired network in field "Name", or create a new one by simply changing the name of the current one.

Original: VirtualBox Networking
Translation to Linux in Russian
Author: Robin Catling
Publication date: May 2012
Translation: Semenenko V.
Date of transfer: October 5, 2012
It all started when I once needed to run a Wordpress CMS instance in a sandbox. The start was simple. It was enough to create a virtual ubuntu server 11.10 as a guest operating system on VirtualBox. But then I discovered that I knew much less about networks and how to set them up than I had previously thought. In particular, about packets, switches and routers. I knew even less about setting up networks in VirtualBox, where all the hardware is presented in programmatically. Several attempts and unsuccessful network settings, the goal achieved - and as a result, I present you this article. Its purpose is to save your nerves based on my own trial and error.

VirtualBox network settings

First, install any version of the VirtualBox virtual machine, starting from 3.0. And you will find in it about the same features compared to those described in this article.
After installing the program, go to the "Settings - Network" menu. The appearance of the opened tab corresponds to the default settings. Any of the virtual machines can be configured to use four network adapters - depending on which one you need in a particular case. But most often in practice only one of them is required. Typically, when installing a virtual machine, a simple network adapter is created by default. This is enough to access the Internet.
Depending on the needs, it may be necessary to create several network interfaces of different types. Or several devices of the same type, but with different settings. This may be required to use both physical and virtual network adapters in the virtual machine. It all depends on which ones are connected.

For my web server running Wordpress CMS, things are a bit more complicated, so let's move on... The "Adapter Type" tab is responsible for setting up the virtual hardware. VirtualBox does an excellent job of acting as a link between the software network card and the physical interface that is installed on the real machine (host). Open the "Advanced" link and you will have access to advanced features of the network adapter. In this article, I will describe in detail all the settings in the order in which they appear, starting with setting the adapter type.

Adapter Type

The VirtualBox virtual machine has built-in software emulation of most of the most common types of network cards for which drivers and protocols are created. The PCnet-FAST III card is the default choice, but in my practice I often choose the Intel PRO/1000MT. I do this if I need the best possible compatibility with the Intel hardware that is installed on my computer. If you have problems setting up your network connection, you can try changing the adapter type to a different one. For the most ancient equipment, a PCnet-FAST II network card is suitable.

Mode

The rather odd-sounding "Promiscuous Mode" is typically used to run a VM as a virtual router on local networks; as a network bridge or host. In this mode, the virtual machine port is able to accept any packets sent for other operating systems; and even for the host. That is, network packets are received that are intended not only for this adapter, but also for other network devices. In 99% of cases, ordinary users do not need "Promiscuous Mode". It is used by network administrators to diagnose network problems.

MAC address (MAC Address)

A MAC address (MAC is short for Media Access Control) is a unique "name" for a device on a network that uniquely identifies and distinguishes it from other adapters and hosts. This address is written for each network device at the physical level in the memory of the interface itself. When creating a virtual network adapter, VirtualBox automatically generates a MAC address for it.
If you need to change an existing MAC address, then this is done by a small button on the right, which generates a new value. In the case of cloning an existing virtual machine, you must create your own unique MAC address for it, which will be different from the address of the original machine.
The checkmark next to the inscription "Cable connected" performs the same role as connecting or disconnecting a physical cable in reality. This setting is responsible for connecting the virtual network adapter to the network. This should not be confused with another more important "Enable network adapter" setting, which enables or disables the adapter itself in the virtual machine.
The "Port forwarding" button opens a dialog box in which you can configure the rules for traffic behavior on a specific adapter; how traffic of a certain type will be moved between the host and the guest virtual machine. These rules apply to network models, which will be discussed a little later. The network models themselves are defined on the Connection Type tab. This setup is the most tricky part of setting up connections in VirtualBox. She gave me the most problems in the experiments.

"Underwater rocks"

There are four types of network connection models and a large number of possible combinations of settings for these connections. In this regard, creating a network in VirtualBox is similar to medieval alchemy - everything is so confusing and illogical here. It would seem that if you follow the correct settings, you will simply get the desired result. However, there are several solutions to the same problem, all of which will initially be correct. But in the end, they will lead to the fact that you will not achieve your goal. Trust me, I already know...

Network connection types

VirtualBox has four ready-made models for connecting to a network:
  • Network Address Translation (NAT), which is the default setting
  • Network Bridge (Bridged)
  • Host Virtual Adapter (Host Only)
Connection type "Not connected" is also a network setting, but it serves only one purpose - to determine possible problems. In this mode, VirtualBox tells the guest operating system that the network card is present, but not connected to it.

Network Address Translation (NAT)

The NAT protocol allows the guest operating system to access the Internet using a private IP that is not accessible from the external network or to all machines on the local physical network. This network setting allows you to visit web pages, download files, view email. And all this using the guest operating system. However, it is not possible for an outsider to directly connect to such a system if it uses NAT.
The principle of network address translation is as follows. When the guest OS sends packets to a specific address of a remote machine on the network, the NAT service running under VirtualBox intercepts these packets, extracts from them the segments containing the address of the sending point (the IP address of the guest operating system) and replaces them with an IP address. host machine address. Then it repackages them and sends them to the specified address.
For example, in your home LAN, the host and other physical network devices have addresses in the range starting with 192.168.x.x. In VirtualBox, NAT adapters have IP addresses ranging from 10.0.2.1 to 10.0.2.24. Such a range is called a sub-network. As a rule, this range is not used to assign addresses to devices on the main network, so such a system is not accessible from the outside, from the host side. The guest OS can perform software updates and web surfing, but remains invisible to other "participants".
The VirtualBox manual describes this point in more detail:
"In NAT mode, the guest network interface is assigned a default IPv4 address in the range 10.0.x.0/24, where x denotes the specific address of the NAT interface, determined by the formula +2. Thus, x will be equal to 2 if there is only one active NAT interface In this case, the guest operating system is assigned an IP address of 10.0.2.15, the network gateway is assigned an address of 10.0.2.2, and the name server (DNS) is assigned an address of 10.0.2.3." (Oracle Corporation, 2012, Chapter 9). The NAT protocol is useful when there is no difference in which IP addresses the guest OSes in the virtual machine will use, since they will all be unique. However, if you need to configure network traffic redirection, or expand the functionality of the guest OS by deploying a web server on it (for example), then additional settings are required. In NAT mode, features such as granting public access to folders and files.

Network Bridge (Bridged)

In a Network Bridge connection, the virtual machine behaves like all other computers on the network. In this case, the adapter acts as a bridge between the virtual and physical networks. On the external network side, it is possible to connect directly to the guest operating system.
The adapter in "Network Bridge" mode connects, bypassing the host, to a device that distributes IP addresses within the local network for all physical network cards. VirtualBox connects to one of the installed network cards and sends packets through it directly; it turns out the work of the bridge over which data is transmitted. As a rule, the adapter in the "Network Bridge" model receives a standard address from the 192.168.x.x range from the router. Therefore, a virtual machine on the network looks like it is an ordinary physical device, indistinguishable from the rest.
Several network devices can be active on a host at the same time; for example, my laptop has a wired connection (called eth0) and a wireless connection (called wlan0). The "Name" field allows you to select which of the network interfaces you would like to use as a bridge on VirtualBox.
In my case, I'm using the wlan0 wireless adapter since it's connected to the router. While the wired eth0 interface doesn't even have a cable.

So my host is assigned an IP address of 192.168.0.2 by the router. The virtual machine in the "Network Bridge" mode is assigned the address 192.168.2.6. It does not matter that VirtualBox transmits and receives traffic as if "through" the host, bypassing it. The result is that the virtual machine becomes just another computer on the local network. If I count my computer and three virtual machines (VMs) running in Network Bridge mode, I have four computers on the physical LAN.

Further more...

The NAT protocol is useful because it protects guest operating systems from the Internet side. But in order to access them from the outside (and on some OS I have web servers installed), you need additional setting to redirect traffic. The "Network bridge" connection type allows you to access them, but the systems in this case become unprotected.
If your network access device (it can be a router, network switch, or settings provided by your ISP) only allows you to provide one IP address per network interface, you may not be able to set up Network Bridge.

Virtual host adapter (Host-only)

With a "Virtual Host Adapter" connection type, guest OSes can communicate with each other as well as with the host. But all this is only inside the VirtualBox virtual machine itself. In this mode, the host adapter uses its own dedicated device called vboxnet0 . They also create a sub-network and assign IP addresses to the network cards of the guest operating systems. Guest OSes cannot communicate with devices that are on the external network, since they are not connected to it through a physical interface. The "Virtual Host Adapter" mode provides a limited set of services useful for creating private networks under VirtualBox for its guest OSes.
Unlike other virtualization products, the NAT adapter in VirtualBox cannot act as a bridge between the hosts' default network device. Therefore, there is no direct access from the outside to the machines "hidden" behind NAT - nor to the programs running on them; nor to data residing on the hosts themselves. Let's look at the following example.

As a rule, the host has its own network address, which is used to access the Internet. This is usually 192.168.0.101. In "Virtual Host Adapter" mode, the host machine also acts as a VirtualBox router and has a default IP address of 192.168.56.1. An internal LAN is created that serves all guest operating systems configured for Virtual Host Adapter mode and visible to the rest of the physical network. The vboxnet0 adapter uses addresses in the range starting at 192.168.56.101. However, you can change the default address if you wish.
Similar to an adapter in Network Bridge mode, Virtual Host Adapter mode uses different address ranges. You can easily configure guests to obtain IP addresses using the VirtualBox virtual machine's built-in DHCP server.
In addition, it must be said that in the "Virtual Host Adapter" mode, the network created by him does not have an external gateway to access the Internet, both for the host and for guest operating systems. It only works like a regular network switch, connecting the host and guest systems together. Therefore, an adapter in "Virtual Host Adapter" mode does not provide Internet access to guest machines; vboxnet0 does not have a default gateway. Additional features for this adapter make it much easier to set up a network between the host and guest OSes, but there is still no external access or port forwarding. Therefore, you may need a second adapter in "Virtual Host Adapter" or "Network Bridge" mode that connects to the guest operating system for full access to it.

Internal Network

If in practice you need to configure the relationship between several guest operating systems running on the same host and can only communicate with each other, then you can use the "Internal Network" mode. Of course, you can use the "Network bridge" mode for this purpose, but the "Internal network" mode is more secure. In Network Bridge mode, all packets are sent and received through the physical network adapter installed on the host machine. In this case, all traffic can be intercepted (for example, by installing a packet sniffer on the host machine).

An internal network, according to the VirtualBox manual, is "a software network that can be visible to selectively installed virtual machines, but not to applications running on the host or on remote machines located externally." Such a network is a set of a host and several virtual machines. But none of the above devices have an output through a physical network adapter - it is completely software, used by VirtualBox as a network router. In general, it turns out a private local area network only for guest operating systems without Internet access, which makes it as secure as possible. A possible application for such a network is a top-secret server with clients intended for development; penetration testing of systems or any other purpose pursuing the creation of an internal network for development teams or organizations. This is an ideal way to block the environment from unauthorized installation of software, downloading or uploading files, visiting services like Facebook during business hours.
So we have considered different types network connections. Each of them has its own settings and is designed for specific purposes. Let's go back to the point where it all started - creating a virtual server to deploy CMS Wordpress on it and test it.

Access to the guest operating system

First, I need Internet access from the guest to install updates, download packages, and other such tasks. I also need access to the network from the host machine. But I don't need the server to be accessible from the external network.
I select the necessary virtual machine from the VirtualBox manager and then go to the "Settings - Network" menu.
I leave the network adapter selected by default in NAT mode. This will allow guest systems to access the Internet through the configured connection of the host where these machines are installed. Guest systems are not visible from the outside on the local network; I also don't have access to any of the guest systems from the host side; similarly, guest systems cannot communicate with each other.

Configuring a virtual host adapter

The easiest way is to use the adapter in the "Virtual Host Adapter" mode provided by VirtualBox by default. It is named vboxnet0 . You can add as many adapters of this type as you need (if there is a need to configure several separate "Virtual Host Adapter" networks). By opening the main window of the VirtualBox guest operating system manager, and selecting "Settings - Network" from the menu, you can configure an existing vboxnet0 adapter or create several more similar ones (vboxnet1 , vboxnet2).
Click on the "Edit" button - the screwdriver icon (third from top to bottom). Clicking this icon will open the default settings. In them, the address 192.168.56.1 is the address at which guest systems access the host. I left it "as is" without changing it.


By default, the vboxnet0 adapter dynamically obtains an IP address during a connection session from a DHCP server. My Wordpress virtual web server needs to have a static IP address. Therefore, on the "DHCP server" tab, I unchecked the "Enable server" box. So my DHCP server is disabled.

Adding a virtual host adapter

I'm going to add another network adapter (in "Virtual Host Adapter" mode) to the guest machine, which will allow me to create a self-contained private virtual network. This network will only consist of the host and any guest operating machine configured in "Virtual Host Adapter" mode.
Therefore, in the guest system settings, I open the "Adapter 2" tab and set the "Connection Type" value to "Virtual Host Adapter". By default, a newly created adapter is named vboxnet0 . "Promiscuous Mode" doesn't matter to me, so I leave it set to "Disable". I also leave the inscription "Cable connected" active.

Guest system setup


I need the guest virtual server to have a static IP address on a network running in "Virtual Host Adapter" mode. Otherwise, the server address will change from session to session, each time you connect. I will be forced to go through the configuration task again and again in order to connect to the host. Therefore, I go into the guest system, open a terminal in it and enter the following two commands in it:
ifconfig eth1 192.168.56.101 netmask 255.255.255.0 up These steps set the specified IP address for the adapter located in the guest system and start that network interface. This address uses the network prefix 192 for home networks, followed by .168 as the starting address of the host ID, .56 to set the sub-network address range; and finally, the final id.1 (host) for the network. An adapter in NAT mode is named eth0 , so it's reasonable to assume that an adapter in Virtual Host Adapter mode is named eth1 . I can use this IP address to test the guest system from the host via SSH protocol or browser.
However, these settings are temporary. If I reboot the system, they will all disappear without a trace. To make them permanent, add (using the root account) the following lines to the /etc/network/interfaces file:
# The hostonly network interface auto eth1 iface eth1 inet static address 192.168.56.101 netmask 255.255.255.0 network 192.168.56.0 broadcast 192.168.56.255 Now, upon reboot, this network interface will start automatically. To check if it has started, I use the ifconfig command, which I enter in the terminal of the guest operating system.

Naming

Since I'm not too "friendly" with numbers and IP addresses, for myself, I always use names for guests instead of assigning IP addresses to them. To do this, I edit the /etc/hosts file on the host machine and add links there. This way I can view the running guests by their names.
In the /etc/hosts file I add the line:
192.168.56.101 ocelotsvr If I add a few more guests to the network, then I just need to edit this file and add the required number of lines. Thanks to this technique, I can easily access any of these systems.

Alternative route

Networking experts may notice that in my configuration there is an alternate route to access the virtual server.
Using the default NAT adapter, I can run an additional configuration that will allow me to access the virtual server from the host without using the "Virtual Host Adapter" network setting.
Using the "Network adapter" settings panel in the guest operating system, you can configure port forwarding in the VirtualBox virtual machine. To do this, go to the NAT adapter settings (button at the bottom of the window) to configure port forwarding. When you click on it, a dialog box will open in which forwarding rules are configured for this network adapter and guest system.
I need to set up two rules; one for accessing the Apache web server on the guest, and one for throttling all other TCP traffic (mostly http requests).
Without further ado, I named these rules Apache and TCP, respectively; both use the TCP protocol. In terms of port number bindings, port 8888 on the host redirects traffic to the guest system for the Apache server; port 2222 on the host redirects traffic to port 22 located on the guest operating system; this setup gives me access to the guest to manage its services. Any other traffic will be rejected by the virtual machine as not matching the rules.

This means that any other guest systems that I run in the virtual machine will not be able to connect to the virtual server, as it simply does not exist. network route under NAT.

Learning how to use VirtualBox is good for everyone. Thanks to this service, you get virtual computers that you can run on your devices without having to buy new hardware. At its core, it is free virtualization software.

To solve many problems, VirtualBox was created. Thanks to this functionality, you get the ability to create virtual computers out of thin air. They don't take up any space on your desk, but they work just like a real PC. They can be created and deleted with a few clicks.

What is Virtual Box? It is a free, open source, cross-platform application for creating, managing and running virtual machines (VMs) - computers whose hardware components are emulated by the host computer, or the device on which the program is running. VirtualBox can run on Windows, Mac OS X, Linux and Solaris.

Why is this needed?

Using virtual machines can be extremely beneficial for a number of reasons. For example, you can run it to try software you think might be dangerous, or you can try a different operating system without changing the way you set up your computer.

You can also use it for security purposes. For example, you can create an online banking-only virtual machine to make sure you don't fall victim to spyware or Trojans getting your data.

How to install VirtualBox?

The easiest way to get latest version VirtualBox - download it from the download page of the official website. There you can find the right version for your platform or? if you're using Linux, you can check out the list of instructions for the various Linux distributions.

For each version of Linux, you are given the option to download the option "i386" or "amd64", 32-bit and 64-bit versions, respectively.

How to install VirtualBox? This process is similar to installing any other program on your platform, so you shouldn't have any problems. If you're having trouble with something, you can always read the installation guide on the service's website.

Using VirtualBox

How to use VirtualBox? When you launch the application for the first time, you will be greeted by the VirtualBox Manager. Here you can create virtual machines, enable or disable them, and configure access to the virtual hardware available to them, as well as make network settings.

Create a virtual machine

In order to set up a network in VirtualBox and get started, you will need to create a virtual machine. This is done in the following way.

The first step to creating any virtual machine is to click the "Create" button in the top left corner of the VirtualBox Manager window - it's a big blue star that's very hard to miss.

This will launch the "New Virtual Machine Wizard" which will guide us through the steps needed to get started.

Enter your name virtual computer. This name is completely up to you, but there are some nuances.

VirtualBox will try to figure out what OS you plan to run in the virtual machine based on what name you enter. If this name mentions "XP", it is assumed that you will be installing Windows XP and configuring it accordingly. However, you can also come up with a random name. You will then have the option to manually select the OS type from the drop-down lists below. When you've done that, click "Continue" to move on to the next step. This example considers Windows for VirtualBox. Below are instructions for installing this OS as a guest and then setting up a network connection.

Choice of RAM

To install a guest OS after starting VirtualBox, you will be prompted to select a volume random access memory, which you want to host in the virtual machine. The more space you give it, the better the application will run, but keep in mind that the memory allocated to the virtual machine cannot be used by the host OS (i.e. the machine running VirtualBox).

So, how much RAM should you allocate to a VM? It depends on a number of factors. If you only plan to use the virtual machine while it's running, you can afford to give it more RAM because you won't be asking the host system to multitask. If, on the other hand, you will be using it at the same time as running many other functions on the host OS, you should better calculate this value. A good general rule is to allocate half of your computer's RAM. So, if your PC has 4GB of RAM, give it 2GB of VM, leaving the host with the rest. If you select this value with a gross error, you will encounter the fact that VirtualBox does not start.

Storage space

The next step is to create a "virtual hard disk" (VHD). This creates a file on your HDD which can be used by VirtualBox to act as a separate hard drive. This allows you to install an operating system without worrying about your existing data being affected.

Make sure Boot Hard Disk and Create a New Hard Disk are selected, then click Continue. This will launch "Create a new master virtual disk". Click "Continue" again to complete the action.

You will then be asked if you want to create a "dynamically expanding" or fixed size disk. Each has its own benefits. The great thing about a dynamic disk is that it only takes up as much space as it contains data. It is also much faster to create than a fixed one of any significant size.

However, you need to keep an eye on it, because its flexibility can also be its negative trait. So you create a dynamic disk and assign 50 GB to it and then put about 20 GB of data on it. Its file will show up as only holding 20 GB of hard drive space, according to your host OS. Therefore, you can take this place with other data and not notice it.

The thing is, if you start the virtual machine and try to add more data to the dynamic disk, you will run into problems - the virtual disk says it still has 30 GB, but in fact it may not already have.

This is also the advantage of a disk with a fixed size. Sure, it's inconvenient when you're trying to figure out how much space you'll need, but then you don't have to worry about it anymore.

This example shows dynamic disks, but fixed disks will work just as well. Make sure Dynamically Expanding Storage is selected, then click Continue again. Next, you will be asked to select a name, location, and size for the new VHD. For most uses, you won't need to change the name or location, but you can do so by clicking on the folder icon next to the text field.

The size you should specify depends on how much material you plan to use. If you just want to use it to run a few programs, the suggested size of 10 GB should be enough. Make sure the settings are correct, then click Continue and Finish.

At this point, all you need to do is check everything and make sure all the settings are set the way you expect. Then you just need to click "Finish" and the virtual machine will be created so you can install Windows.

Booting a guest OS in VirtualBox

How to use the service further? Now it's time to start the virtual machine for the first time. Make sure the new virtual PC you just created is selected in the VirtualBox Manager window, then click the Start button at the top of the window. When the service starts, you will be greeted with the First Run Wizard window to help you get ready to install Windows XP. Click Continue. It will then ask you if you want to use the installation media - a CD or an image on your hard drive (usually in the form of an .iso file). Once you have chosen your option, click Continue, then Finish.

If you were unable to open the VirtualBox virtual machine after the above settings, you probably did not properly allocate space for RAM or HDD. In case the reboot does not solve the problem, repeat the previous steps again.

Since nothing is installed on the virtual hard disk, the program will automatically load Windows installation. It will take some time to load all the necessary OS files, but eventually you will see a screen that shows a list of existing partitions and unallocated space on the computer.

After that, you have to set up XP, so press Enter. You will be asked how you want to format the drive. You need to select the option "Format partition using a file NTFS systems(Quick)". Make sure you select the "Quick" option or you will be waiting for a very long time!

Windows Setup will then format the VHD and then start copying the files to the drive. Your participation in this process is not required. When the files are copied, Windows Setup will automatically restart the computer to proceed to the next step.

When the PC restarts, it will try to boot from the CD using the "Press any key to boot from CD..." window. Ignore it! If you do, you will repeat the previous step again for no reason.

You can prevent this system issue by right-clicking on the CD icon at the bottom of the virtual machine window and clicking "Remove Disk from Virtual Disk". As soon as this window closes, you will see a familiar screen Windows boot XP before it switches to the second stage of the installation.

Once the "Windows XP Setup Wizard" is displayed, click "Next" to start it. First you will be prompted to set the regional and language options, which are mainly related to clicking "Customize ..." (to select a country), and then "Details" if you need to change the keyboard layout.

Once everything is selected, click Next again. After that, you will need to enter the computer name and administrator password. It's better to choose a title that makes some sense, rather than a random string of automatically generated characters. How complex you want to make the administrator password depends on how important the security of the virtual machine is.

After clicking "Next", you will see the date and time settings that you do not need to change. If you click this button again, the window will disappear for a while, Windows will apply all settings and continue with the installation. Now you can use the Guest Additions in VirtualBox.

After a minute or two, another window will appear, this time for network settings. It is more convenient to choose the first option (a network that does not have a domain). This requires you to enter a name. working group- Rward by default, and all default values. However, you may need to select "Direct3D Support" when asked to define components.

How to work with the network?

Networking in VirtualBox is extremely efficient, but setting it up can be a little tricky. To get to the bottom of this, let's look at the various ways to set up a VirtualBox network, with a few pointers on which configurations to use and when.

Oracle VM VirtualBox 5.1 allows you to configure up to 8 virtual network adapters (network interface controllers) for each guest virtual device(although the GUI only has 4).

Main modes:

  • Network Address Translation (NAT).
  • bridge networks.
  • Internal network.
  • The network is for hosting only.
  • NAT with port forwarding.

Oracle Virtual Box offers them as based on the guest OS type you specify when you create the VM, and you rarely need to modify them. But the choice of network mode depends on how you want to use the device (client or server) and whether you want other computers on your network to see it. So, you should look at each VirtualBox network configuration mode in a little more detail.

Network Address Translation (NAT)

This is the default mode for new VMs and works great in most situations where the guest OS is a "client" type (i.e. most network connections are outgoing). Here's how it works.

When the guest OS boots up, it usually uses DHCP to obtain an IP address. Oracle VirtualBox will send this DHCP request and inform the operating system of the assigned IP address and gateway address to route outbound connections. In this mode, each virtual machine is assigned the same IP address (10.0.2.15) because each virtual machine thinks it is on its own isolated network. And when they send their traffic through the gateway (10.0.2.2), VirtualBox rewrites the packets so they appear as if they came from the host, not from the "guest" (running inside the host).

This means that the guest OS will work even if the host moves from network to network (like a laptop moving between locations), from wireless to wired connections.

However, how does another computer initiate a connection to it? For example, you need to connect to a web server running on a guest computer. This is not possible (usually) using NAT mode because there is no route to the guest OS. Thus, for running VM servers, you need a different network mode and a different VirtualBox network setup.

NAT connection (network characteristics):

  • Guest OSes are on their own private network.
  • VirtualBox acts as a DHCP server.
  • The NAT mechanism of VirtualBox translates addresses.
  • The target servers display traffic originating from the VirtualBox host.
  • No configuration is required for the host or guest OS.
  • Works great when the "guests" are clients but not servers.

Bridge networks

Bridged Networking is used when you want your virtual machine to be a full member of the network, i.e. equal to your host device. In this mode, the virtual NIC is "attached" to the physical one on your host.

This is because each VM has access to the physical network just like your host. It can access any service on the network - external DHCP services, name lookup services and routing data, and so on.

The disadvantage of this mode is that if you run a lot of virtual machines, you can quickly run out of IP addresses or your network administrator will be overwhelmed with requests for them. Second, if your host has multiple physical network adapters (such as wireless and wired), you must reconfigure the bridge if it reconnects on the network.

What if you want to run servers in a virtual machine but don't want to involve a network administrator? Maybe one of the following two modes is right for you, or you need a combination additional options, such as NAT vNIC + 1 Host-only vNIC.

Bridge network characteristics:

  • VirtualBox bridges are for the host network;
  • good for any guest OS (both client and server);
  • use IP addresses;
  • may include guest configuration;
  • best suited for production environments.

Internal network

When you configure one or more virtual machines to run on an internal network, VirtualBox ensures that all traffic on that network stays inside the host and is only available to the device on that virtual network.

The internal network is a completely isolated system. It is well suited for testing. In it, using a virtual machine, you can create complex internal networks that provide their own services (for example, Active Directory, DHCP, etc.). Note that even the host is not an element of it.

This mode allows the virtual machine to run even if the host is not connected to the network (for example, on a plane). However, with this type of connection and network setup, VirtualBox does not provide "convenient" services like DHCP, so your device must be statically configured or provide a DHCP/Name service.

Multiple internal networks are allowed. You can configure VMs to allow multiple network adapters to be in internal and other networking modes and thus provide routes if needed. But all this looks complicated and inaccessible to a non-specialist.

What if you want the internal network to host the VirtualBox host, giving the guest OS IP addresses? To do this, you may need to configure the network for the host only.

Characteristics of the internal network:

  • guest OSes can see other "guests" on the same internal network;
  • the host cannot see the internal configuration;
  • network configuration required;
  • even if the host is not a member of the connection, the internal network can be shared with a bridged connection;
  • well suited for a multi-user network.

Host-only network

Works much the same as an Internal Networking connection where you specify which network the guest server is on. All virtual machines on this network will see each other and the host. However, other external devices cannot see "guests" on this network, hence the name "host only".

It is very similar to an internal network, but the host can now provide DHCP services. To set up such a connection, go to VirtualBox Manager and select the default settings.

Network characteristics:

  • VirtualBox creates a private internal network for the guest OSes and the host sees the new NIC software.
  • VirtualBox provides a DHCP server.
  • Guest OS cannot access the external network.

NAT with port forwarding

Now you can imagine that you have learned enough modes to handle each case, but there are exceptions. What if the development environment is on a laptop, for example, and you have one or more virtual machines that need other computers to connect to? And you are constantly forced to use different client networks.

In this scenario, NAT will not work because the external machines must be bridged. This is probably a good option, but you may need IP addresses. In addition, the software is not always able to cope with changing networks.

If you use the internal network, then it may turn out that your virtual machines required to be visible on the network. What to do in such cases?

Set up the virtual machine to use a NAT network, add port forwarding rules, and connect external computers to the "host". The port number and connections will be redirected by VirtualBox to the guest OS number.

For example, if your virtual machine is running a web server on port 80, you can set up the above rules. This provides a mobile demo system that does not need to be reconfigured each time you connect your laptop to a different LAN/Network.

Ultimately, VirtualBox has a very powerful set of options, allowing you to customize just about any configuration you might need. To choose the option you need, study the VirtualBox instructions on the official website.

PC users can use different types of operating systems in their work. Sometimes it is very necessary, being in one OS, to use the functions of another, and rebooting is undesirable. There is a great solution - "virtual machines". Among the most famous in the global IT market is VirtualBox. What are its features? How is the network setup necessary to work with VirtualBox done?

What is Virtual Box

VirtualBox is, as we noted above, a "virtual machine". In other words, this is a software environment that allows you to load one or another operating system in almost full-function mode while the user is in the interface of another OS.

That is, for example, if a person is running Windows, then using VirtualBox, he can run (and before that install) on a Linux PC without rebooting. The practical usefulness of this function may lie, for example, in the fact that when working with Windows programs, you can fully use the functions of the server OS of the Linux line, which in some cases are indispensable. By the way, the reverse procedure is also possible.

The full name of the "virtual machine" in question is Oracle VM VirtualBox, as it was developed by the famous American corporation. Consider the main features of the solution from Oracle.

Features of Virtual Box

VirtualBox is a great alternative to solutions like Wine, which are used when a Linux user needs to run a Windows program. At the same time, the activation of Wine does not guarantee the successful launch of Windows-oriented software. In turn, the "virtual machine" allows you to download the appropriate OS interfaces from Microsoft and use them with almost the same functionality as when booting Windows separately.

So, when solving management problems, such capabilities are extremely in demand. The most important thing for the full use of the potential of Windows or Linux through VirtualBox is to configure the network in accordance with the correct algorithms.

Terms of use

One of the main advantages of VirtualBox is that it is free. At the same time, this solution is actually released in a single version, and therefore, having mastered the intricacies of working with it, you can easily use it later without fear that the developer will release fundamentally new interfaces. Note, however, that Oracle has created an additional package for the "virtual machine" - Expension Pack, which includes such solutions as, for example, an RDP server, with which you can connect to a virtual machine remotely using the appropriate type of protocol. An extended package for VirtualBox for personal purposes - that is, subject to non-commercial use - is supplied to enthusiasts of useful IT solutions for free.

Capabilities

What are the most noteworthy features of the VirtualBox program?

First of all, this is virtualization on platforms like x86 - no need to support Intel VT, as well as AMD-V.

The program is characterized by an intuitive user-friendly interface. Russian language is also supported in VirtualBox. Setting up the network and solving other problems will thus be facilitated for Russian users.

VirtualBox is a cross platform solution. It is suitable for Windows, Linux, Mac OS.

There is support for processors with multiple cores, as well as computers that have multiple corresponding chips installed.

There is Guest VM Additions, which allows you to optimize communications with the operating system on which the program runs.

The performance of a virtual machine, according to many IT professionals, is at the highest level.

One of the key tasks in preparing to work with VirtualBox is setting up the network. Consider its main nuances of its solution.

Installing a virtual machine

So, we have to configure the VirtualBox network. Let's study the key nuances of installing it on a user's computer, as well as the algorithms for the basic steps for setting up this software. First you need to download the distribution package of the program on the virtualbox.org website and install the solution on a PC. What nuances can accompany the solution of this problem? For example, you should confirm the installation of the virtual interface required for the network to work. In this case, the actual connection may be temporarily deactivated.

Key virtual machine settings

Next, we launch the program. The main window of the interface will display a list of virtual machines that can be run on a PC. At the very first boot of the program, it will most likely be empty. Therefore, the user will need to create a virtual machine on their own. To do this, click the appropriate button, then select the type of virtual machine and its name. The OS that many users prefer to install on VirtualBox is Ubuntu. Setting up a network with its help is carried out fairly quickly, the accompanying nuances are easy to master.

After selecting the type of virtual machine in the settings, you must specify how much RAM the program can use. The recommended value is 1 GB. After that, you need to create a virtual disk space - this is done on the computer's hard drive. To do this, you need to specify in the settings that a file type such as VDI will be used. It should also be noted in the program that the disk will be dynamic. After that, we specify the size of the hard drive, for example, 8 GB (you don't need too much disk space to run the "virtual machine").

Consider how to set up a "virtual machine" from Oracle. It can be run in the interface of almost any version of Windows, including the most common in the world - Windows 7.

The main nuances of setting up VirtualBox in Windows 7

After installing the program, for example, in Windows 7, you will need to configure some of its key options. In the main window of the VirtualBox interface, right-click on the created "virtual machine" and select the "Properties" option. The key point that interests us in the corresponding interface is the type of buffer between the two systems: the host and the guest. The corresponding option is in the "General" tab. It's best to tell the program to use a bidirectional buffer.

It is also useful to select the "File" menu item, then go to "Settings". In the "General" section, select the "Folder for machines" list. We mark the option "Other" and specify the folder where the files of the virtual machine will be located. In the Input section, you can configure a key that redirects keyboard input and mouse manipulation to the virtual machine interfaces. You can also configure the display - for example, in terms of the maximum

Launching VirtualBox and installing a second OS

After the basic settings are made, you can start the "virtual machine". To do this, select its name from the list in the main menu and click on the "Start" button. After that, an interface will open with which you can install the required OS. Its distribution, therefore, must be ready - for example, in the form recorded on a CD or DVD. After the OS is installed, we can proceed to such a stage as directly setting up the VirtualBox virtual network.

Network Setup: Key Options

You must select the type of virtual OS and click the "Configure" button. After that, go to the "General" tab. Here we are interested in the "Network" section. You must select a connection type such as bridge. It assumes that a channel will be formed between the PC network card and the virtual machine, with the help of which the corresponding resource of the current OS can be used in another operating system. Note that in the "Shared Folders" section, you can manage the corresponding elements for storing files that appear during the exchange between the PC and the virtual machine.

Setting up a network in a "virtual" Ubuntu OS

As we noted at the beginning of the article, the optimal virtual environment when using VirtualBox is Ubuntu. Setting up the network by using this operating system can be implemented as part of the following algorithm. To begin with, you should download one of the OS versions that is best adapted to solve the problem in question. You need to go to releases.ubuntu.com, then select version 14.04 LTS. After that, you should download the ISO image of the operating system. If the user has a 64-bit PC, then the appropriate type will be needed. Next, using the VirtualBox interface, you need to start the OS installation process (we discussed above how this mechanism works). After installing the “virtual” Ubuntu, we proceed to the main stages of such a procedure as setting up the VirtualBox network. Windows 7 can also be used for this task.

We can use a remote server configuration script using the SSH protocol - in fact, in order to use this feature, we installed a “virtual machine”. Among the most convenient tools for working with SSH in Windows is the PuTTY program. It must be downloaded from putty.org. But before that, you need to correctly install Ubuntu - some nuances accompany this task. Let's consider them.

OS installation features in a virtual machine

At the beginning of the Ubuntu installation, the system will ask for the desired language settings. After entering them, the installation of additional components will begin. During the OS installation process, the system may attempt to configure the network with DHCP, but this should only be done if this type of server is on the network. If they are not present, then the user will be prompted to set the appropriate settings manually. But at the current stage of the installation, this is not necessary - you can skip this step.

Among the options that are important to us is the name of the computer. It might sound something like this: computer227.computer227network.com. This, of course, is not an Internet address, but only the required network identifier of the PC. Next, you need to configure Accounts user. It must be borne in mind that the word admin cannot be used as a nickname - this is the specificity of the Ubuntu OS (it is reserved in the system). You can choose an option such as userhost, for example. Password - any that will be convenient for the owner of the PC.

Next stage Ubuntu installations- Setting the time and time zones. It is desirable to indicate real.

After setting up the hard drive, the download of the main files will start. After it finishes, the system will prompt you to configure APT packages - but this is only important if the user wants to install a proxy server. We will agree that we will not use it on the network, so this configuration step can be skipped.

Next, the system will ask if it is necessary to install. Many IT specialists prefer not to carry out this procedure, since in this case you can fully control the processes occurring in the OS. Then, in the interface window, you need to mark OpenSSH as the type of software used.

During the further Ubuntu installation process, the system will ask if the GRUB bootloader should be installed in the appropriate area of ​​the disk. After the OS is fully installed, you need to restart the PC.

Basic network options

The next step in working with VM VirtualBox is setting up the network using the interfaces of the Ubuntu OS. It is necessary to enter the operating system by entering the username and password that we determined during the installation.

The next necessary action is to obtain access rights at the ROOT level, that is, the superuser. The corresponding option must be activated.

This can be done by entering the command: sudo su. Another option is to enter sudo passwd root at the command line with a password. Actually, these are the main settings at this stage. You can download the PuTTY program and manage the Ubuntu server through a virtual machine.

Nuances of network settings

What are the nuances regarding working with Oracle VirtualBox? Network setup may require adjustments to a number of other options. Which ones?

For example, you may need to configure the server in terms of establishing a permanent IP address on it. To do this, you need to make the appropriate changes to /etc/network/interfaces. This is done with the following command: nano /etc/network/interfaces. After that, you can restart the network with the following command: /etc/init.d/networking restart.

Then you need to make adjustments to /etc/hosts using the appropriate nano command. The following settings must be present in the file structure:

127.0.0.1 - for localhost;

192.168.0.1 (if the IP address of the computer on the local network differs from the specified one, we write the correct one) for the server address specified above, that is, computer277.computer277network.com computer277.

Next, you need to synchronize the clock running in the system with a time server on the Internet. To do this, enter apt-get install ntp update at the command line. This completes the configuration. After that, you can fully use Oracle VM VirtualBox. simple enough. The subsequent use of Ubuntu using a "virtual machine" assumes the possibility of using the widest set of functions of this server OS.

Universal tool: works in Windows XP

Does Oracle's VM run relatively outdated versions Windows like XP? Yes, it is quite. In accordance with the considered algorithm, it is possible to configure other Operating Systems using VirtualBox. Setting Windows networks XP, of course, will be implemented in slightly different ways. In particular, the command line, as in Ubuntu, will not be used during this procedure.

However, Windows XP has LAN controls that are quite understandable even to an unprepared user, and working with them should not be accompanied by tangible difficulties and failures.

Of course, in addition to Ubuntu, other operating systems from the Linux line are compatible with the "virtual machine" algorithms. Among those that are great for use with VirtualBox is CentOS. Network setup in this Linux distribution will be based on algorithms that are generally similar to those that we used when working with Ubuntu.