System integrator. Wmware workstation network setup in virtual machines How to make virtual machine network and main

VirtualBox allows virtual machines to use the network connections of the host system, as well as create virtual networks for virtual machines.

Using the GUI tools, up to 4 network adapters can be configured for each of the virtual machines registered in VirtualBox.

The procedure for setting up network interfaces is well described in the proprietary Oracle VM VirtualBox® user manual in English.

For each virtual machine You can emulate up to 4 network adapters. Each of the network adapters can work in one of 6 modes:

  • Not connected. In this mode, the adapter is present in the guest system, but behaves as if the network cable is not included in it.
  • NAT. In this mode, the adapter uses the host system's network settings when interacting with the physical host network and other external networks. The VirtualBox network subsystem translates IP traffic with the virtual machine's source IP address into traffic with the host system's network adapter source address (Network Address Translation). The implementation of NAT in VirtualBox has certain limitations related to support for ICMP protocol, broadcast UDP traffic and virtual private network technologies. This mode is used by default.
  • network bridge. In this mode, the VM network adapter connects to the host system network adapter and processes network packets directly bypassing the host system network stack (the host system adapter works with the VM adapter in bridge mode).
  • Internal network. The network adapters of the Virtual Machines are interconnected to form an isolated network segment.
  • Virtual host adapter. A network that combines a host system and virtual machines included in this segment into a given segment. For this mode, VirtualBox creates a software network interface on the host system and sets an IP address on it.
  • Universal driver. The user selects the network adapter driver, which can be included with VirtualBox or loaded with the VirtualBox add-on package. On the this moment There are 2 drivers that implement 2 virtual adapter modes:
    • UDP Tunnel. Mode for communication between virtual machines running on different hosts. Works on existing network infrastructure.
    • VDE(Virtual Distributed Ethernet). This mode can be used to connect distributed virtual machines to a Virtual Ethernet Switch on Linux or FreeBSD hosts.

For each of the 4 virtual machine network adapters, you can choose one of 5 drivers that emulate real network adapters from various hardware manufacturers or the Virtio-net driver, which is part of the open-source KVM project. The Virtio-net driver avoids the complexity of network hardware emulation and improves network performance. Linux guest kernel version 2.6.25 and older can support the Virtio-net adapter. For Windows 2000, XP, and Vista guests, the driver for the Virtio-net adapter can be

Setting up a virtual network in virtualbox. How to correctly and quickly create and configure a virtual network, read our detailed instructions.

In this article, we will look at creating and configuring a virtual computer network using the VirtualBox program.

VirtualBox Network Modes

In the right column, go to the "Network" menu.

Each virtual machine has 4 conditional adapters, each of the adapters has 5 configuration profiles, which we will discuss below.

By default, when creating such a machine, the adapter is configured to work in NAT mode, which allows access to .

Let's take a closer look at each type of network interface.

NAT

Network Address Translation- a mechanism in networks built using the TCP / IP protocol that converts the IP addresses of transit packets.

This setting network interface allows the guest operating system access the Internet using a private IP address that is not accessible from the outside.

This principle is used in home routers.

The device has 1 external, "white" IP address, issued by the provider for identification in the global network, and many internal, "gray" IP addresses set by the user for the interaction of network devices in .

Note! This VirtualBox network adapter setting is needed primarily for Internet surfing. In this case, it is not possible to connect to the guest operating system from the outside. This feature is very useful, because it allows you to protect remote machines from external network attacks. To remove this restriction, you must perform a port forwarding operation.

Network bridge (Bridge)

Using this type of connection, the virtual machine is no different from the host machine for other network members.

The network adapter in this configuration serves as a bridge between the virtual network and the physical network.

The conditional network adapter connects and works directly with bypassing the host machine.

If the computer has several network interfaces, it is possible to specify through which of them the interaction will be carried out (field "Name").

It makes sense to use this type of adapter operation when you need to provide access to the virtual machine to other members of the local physical network.

Virtual host adapter

With this mode of operation, it is possible to interact both between virtual machines and between a virtual machine and a host.

In this case, a special device is used - vboxnet0, which creates subnets and assigns IP addresses to the guest OS.

Important! When using a host adapter, there is no way to communicate with other members of the physical local network. This mode will be useful when it is necessary to establish interaction between the guest and host machines.

Internal network

As the name implies, this type of interaction involves connecting guest operating systems to a single internal network.

As in virtual host adapter mode, networking is done in software, bypassing the physical interface.

It should be noted that the difference from the previous mode of operation lies only in the inability to work with the host machine.

Universal driver

Allows you to independently select a driver for the network adapter. The driver may be included with VirtualBox or downloaded with an update package.

Today there are 2 drivers for two modes of operation of the virtual adapter:

UDP tunnel. Used to communicate with machines running on .

VDE. Used to connect virtual machines to a virtual Ethernet switch on FreeBSD or Linux hosts.

It should be noted that the VDE mode allows you to emulate L2 / L3 switches and STP, WAN, VLANs protocols.

Network setup for VirtualBox basic modes

NAT

Select this type of connection and start the remote machine. After starting, you need to set the network adapter to DHCP client mode.

network bridge

If in your home network IP addresses are issued automatically (for example, a DHCP server is set up on the router), then you need to make sure that the DHCP client mode is set in the network adapter properties of the guest OS.

If network settings are assigned manually, you should enter them in the appropriate fields.

In this mode, we have access to local and global networks.

Virtual host adapter

For this mode, you need to make some presets. In VirtualBox, go to the "File" menu, "Settings" submenu.

Select the "Network" item and go to the "Host Virtual Networks" tab. Click on the network adapter icon with a + sign.

This creates a vboxnet0 virtual adapter.

Note! Vboxnet0 can be configured by clicking on the screwdriver icon. In the DHCP Server tab, you can enable and configure the DHCP server, which will automatically assign IP addresses to guest machines operating in virtual host adapter mode.

After that, in the network adapter settings of all virtual machines that need to be combined into one subnet, you need to select the virtual host adapter mode, and select vboxnet0 as the working profile.

Internal network

To combine several virtual machines into one virtual network, you need to select the "Internal network" connection type in the profile of all guest OSes, and then enter the name of the virtual network or use the standard one - intnet.

Depending on the tasks set, combining the work of interfaces will help to achieve success in their implementation.

For example, by assigning one adapter to work in the "Internal Network" mode, and the other in the NAT mode, we will get a virtual network with Internet access.

Configuring the VirtualBox network

Creating and configuring a VirtualBox OS Windows 7.8 virtual network

For each network interface, you can select the hardware that will be connected to the virtual machine. VirtualBox can emulate the following network hardware:

AMD PCNet PCI II (Am79C970A);

AMD PCNet FAST III ( Am79C973, default);

Intel PRO/1000 MT Desktop (82540EM);

Intel PRO/1000T Server (82543GC);

Intel PRO/1000 MT Server (82545EM);

Paravirtualized network adapter (virtio-net).

The PCNet FAST III network card is installed by default. it is supported by almost all operating systems, as well as the GNU GRUB boot manager.

And indeed, this card in NAT mode installed well and without problems in Windows 98:


PCNet FAST III network cardin NAT mode, it is also installed well and without problems in Windows XP:



1.Network Address Translation (NAT)

Network Address Translation (NAT) mode provides the easiest way to access the external environment from a virtual machine. It usually does not require any host or guest configuration. Therefore, it is the default network mode.

A virtual machine with a network interface in NAT mode connects to the network just like a real computer connects to the Internet through a router. The "router" in this case is the VirtualBox network module, which processes the network traffic of the virtual machine. The disadvantage of the NAT mode, as in the case of a local network behind a router, is that the virtual machine is not accessible to the external network (internet); you cannot process network requests until you set up port forwarding.

The virtual machine receives the network address and other settings on the local network from the DHCP server built into VirtualBox. Thus, the IP address assigned to the virtual machine is different from the network address of the host network. It is possible to configure the use of several network cards in a virtual machine in NAT mode, then the first card will belong to the local network 10.0.2.0, the second 10.0.3.0, etc.

In NAT mode, the guest network interface is assigned by default an IPv4 address on the network 10.0.x.0/24 , where x is the VM interface sequence number plus 2. That is, x is 2 if there is only one active NAT interface. In this case, the guest is assigned an address 10.0.2.15 , the gateway address is set to 10.0.2.2 , and the name server (dns) 10.0.2.3 .

Indeed, practice has confirmed that with the NAT mode in VirtualBox, the network in virtual machines Windows XP and Windows 98 are configured without any difficulties. It is enough to set the NAT mode when installing the system into the VirtualBox virtual machine and the network will be established. Also, the network is installed without problems if the card is connected after the installation of the operating system.

2. Execution of the ipconfig /all command for the NAT mode of virtual machines.

Windows 98 has the following network settings:





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 stands 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. If you are cloning an existing virtual machine, you will need to 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 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 update software 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 sharing folders and files are also not available.

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 am using wireless adapter wlan0 because it is 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 OS, but still there is 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).

The internal network, according to the VirtualBox manual, is " program network, which may be visible to selectively installed virtual machines, but not to applications running on the host or on remote machines located outside". Such a network is a collection of a host and several virtual machines. But none of the above devices has 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 network only for guest operating systems without Internet access, which makes it as secure as possible.A possible application of such a network is a top-secret server with clients, designed for development, penetration testing, or any other purpose to create 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 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 to the adapter located in the guest 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, you need to add (using account root) to the /etc/network/interfaces file with the following lines:

# The host-only 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 network setting"Virtual Host Adapter".

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.

Setting up a local network between a computer and a virtualbox virtual machine is pretty easy, you just need to know some of the nuances, which I will cover in this article.

The first step is to set up the network in virtualbox. The virtual machine must be turned off. We go to "Settings -> Network", select an unused adapter, turn it on and select the connection type - "virtual host adapter":

In windows, the network can be checked with the "ipconfig" command:

On Linux OS, from the terminal, the network can be checked like this:

ifconfig

In response, you should see working network interfaces:

By ip, you can guess which interface is responsible for organizing a local network between a computer and a virtual machine, by default (if you didn’t configure ip in virtualbox yourself), such an ip should look like this: 192.168.56.* (instead of *, it usually happens to be 101 or 102 and etc.).

This ip must be used to access the virtual machine.

The default ip is given by the dhcp virtualbox server. For convenience, you can set a static ip address in the virtual machine itself. For example, in windows this is done by editing the network properties. In the linux interface, everything is similar, but how to do it in the terminal, without a graphical shell, will be shown below, using the example of adding a new network interface to ubuntu server.

In linux, it happens that the LAN interface between the computer and the virtual machine is not enabled by default, and as a result, there is no local network. In this case, you must raise the LAN interface between the computer and the virtual machine manually. Next, the process of enabling the network interface in ubuntu server will be described.

First you need to find the name of the network interface that we need. In the terminal we type:

As a result, you will get a list of all network interfaces.

We find the desired interface, it is most often the last one. Perhaps most likely it is either eth1 (for ubuntu server 14.04) or enp0s8 (for ubuntu server 16.04), it all depends on the number of network adapters connected to the virtual machine.

Nano /etc/network/interfaces

File /etc/network/interfaces for ubuntu server 14.04:

# The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eth0 iface eth0 inet dhcp

At the end of the file, add the line (for ip set dynamically):

Auto eth1 iface eth1 inet dhcp

For static ip:

Auto eth1 iface eth1 inet static address 192.168.56.101 netmask 255.255.255.0

Instead of eth1, there may be another interface name, depending on your configuration.

After that, you need to restart the virtual machine and type the command again:

ifconfig

The eth1 interface, or the one you specified, should appear in the list.

/etc/network/interfaces file setup for ubuntu server 16.04:

# The loopback network interface auto lo iface lo inet loopback # The primary network interface auto enp0s3 iface enp0s3 inet dhcp

Here the interface is called enp0s3 instead of eth0. According to the data received by the "ip a" command, in my case, at the end of the file you need to add:

Auto enp0s8 iface enp0s8 inet dhcp

After making changes, you also need to restart the virtual machine, or you can restart only the networking service:

sudo service networking restart

On ubuntu server 14.04, it doesn’t always restart for me, it just continues to work, with ubuntu 16.04 everything is fine in this regard, but for complete certainty, I think it’s better to restart the virtual machine anyway.

After restarting the machine and typing the ifconfig command in the terminal, the enp0s8 interface should appear in the resulting list of network interfaces.

What to do if the network interface still does not work?

There are two main options: either you specified the wrong interface in the /etc/network/interfaces file - in this case, carefully look at the list of all available network interfaces with the “ip a” command again and select the one you need. Or the virtual OS does not see the network adapter at all. In this case, most likely the OS does not have suitable drivers for this adapter. This problem can be solved by changing the adapter type, for example, to "paravirtual network (virtio-net)":

You can experiment with the type of adapter to achieve the desired result.

ssh access to virtual machine in virtualbox

After successfully setting up a local network between the computer and the virtual machine, you can connect to it, for example, via ssh. To do this, we type the ip address, about which I wrote at the beginning of the article, in the ssh client and rejoice at the successful connection)