Virtualbox host only ethernet adapter linux

VirtualBox: two network interfaces (NAT and host-only ones) in a Debian guest on Ubuntu

I created a Debian VM on VirtualBox with two interfaces: a NAT one (for accessing internet) and a host-only one. However, I do not know how to make both interfaces work at the same time. If I the define the host-only as the adapter 1, I can access my VM from the host but not the internet; if I define the NAT one as adapter 1, I can access the internet but cannot reach my guest Debian. So, how could I make both interfaces work together? Note: I am still trying to map some port from my host to the SSH port from my guest SO, so there is no need to suggest me to do it 🙂 EDIT: This is the output of ifconfig when the first adapter is the host-only one:

eth0 Link encap:Ethernet HWaddr 08:00:27:f6:b2:45 inet addr:192.168.56.101 Bcast:192.168.56.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fef6:b245/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:495 errors:0 dropped:0 overruns:0 frame:0 TX packets:206 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:48187 (47.0 KiB) TX bytes:38222 (37.3 KiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:8 errors:0 dropped:0 overruns:0 frame:0 TX packets:8 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:560 (560.0 B) TX bytes:560 (560.0 B) 
Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 192.168.56.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 
eth0 Link encap:Ethernet HWaddr 08:00:27:f6:b2:45 inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fef6:b245/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:53 errors:0 dropped:0 overruns:0 frame:0 TX packets:59 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:6076 (5.9 KiB) TX bytes:5526 (5.3 KiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:16 errors:0 dropped:0 overruns:0 frame:0 TX packets:16 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:1664 (1.6 KiB) TX bytes:1664 (1.6 KiB) 
Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 10.0.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 0.0.0.0 10.0.2.2 0.0.0.0 UG 0 0 0 eth0 

Источник

Читайте также:  Cades linux amd64 tar gz

How to Use VirtualBox Host-Only Networking

VirtualBox is one of the popular virtualization platforms from Oracle Corporation. With VirtualBox, we can run multiple operating systems simultaneously. We do not need to mess up with our main Host OS. It has many powerful networking features to set up any desired configuration. There are six networking modes supported in VirtualBox, namely:

1. Not Attached (network card is present, but the cable is unplugged)

2. NAT (Network Address Translation)

What will we cover?

In this guide, we will learn how we can configure Host-only networking mode in a VirtualBox virtual machine. We will use two virtual machines: 1) Fedora 34 2) Ubuntu 20.04. After connecting them in a Host-only mode, we will check if both of them can ping each other and the Host machine. Let us first understand the concept and how to use the Host-only networking mode.

VirtualBox Host-only Networking Mode

Host-only networking performs the combined functions of bridged and internal networking modes. In bridge mode, a virtual machine can communicate with the host machine and other virtual machines because they share the same physical interface of the host machine. Similarly, in the case of internal networking mode, virtual machines can only talk to each other but cannot communicate with the host machine and any other machine outside of their set as they are not connected to any physical interface.

Note: It should be clear that all the functions that can be achieved with internal networking can also be performed through Bridge Networking. But in the latter case, there is a security risk of passing virtual machine traffic through the physical interface of the Host.

A Host-only networking mode creates a network between the Host machine and virtual machines using a software interface (NIC). This means that in this mode, a virtual machine can connect to the Host and other virtual machines. In the case of the Internal networking mode, the connectivity is limited to virtual machines on the same Host. Also, unlike the Internal networking mode, Host-only mode provides DHCP services to assign IP addresses to the connected virtual machines. For this mode, there is no need for the physical interface of the host machine. Instead, the software interface (named as vboxnet) will perform the same function.

Читайте также:  Python на линукс запустить

In the case of virtual appliances which are already configured, the Host-only networking helps a great deal. These appliances contain several virtual machines running different applications like database servers, web servers, etc. We can connect the web server and database server using a Host-only adapter. In this way, both can communicate with each other, but cannot connect to the outside world. This is the desired setup for securing a database server from direct access from the outside world. But in the case of a web server, we need to access it from all over the world. So to get this done, we will activate the second adapter in the VirtualBox networking option and connect it to the Bridge adapter.

Enabling Host-only Networking Mode

To enable Host-only networking mode in VirtualBox, follow the steps below:

Step 1. We need to create a Host-only network adapter. For this, go to the “File” option in the VirtualBox menu bar and select the “Host Network Manager”.

Step 2. In the new pop-up window, select the green icon corresponding to “Create Host-Only Network”. A new adapter, “vboxnet0”, will be created. The IP range of this adapter can be set from manual mode to automatic mode using the “Properties” menu.

Note the IPv4 address and mask for the adapter: 192.168.56.1/24. We will need it later when configuring IP addresses on virtual machines.

Step 3. Once the virtual adapter is created, we can use it with the Host-only networking mode. Now select the virtual machine from the list on the left pane. Right-click the name of the virtual machine and select the option “Settings” or select the “Settings” icon from the right pane.

Step 4. In the new pop up window, select the label corresponding to “Network”.

Step 5. On the right pane, under Adapter 1 tab:

Читайте также:  Oracle linux remote desktop

1. Check to mark the “Enable Network Adapter” option.

2. Under the “Attached to” label, select “Host-only Adapter” option from the drop down menu.

3. From the drop down menu with the label “Name”, select the name of the virtual adapter (vboxnet0 in our case). Save settings and exit.

Step 6. Now launch your virtual machines and check the IP of the interfaces for both. You can use the “ip a” command for this. Let us configure each machine:

As you can see, there is no IP address for the enp0s3 interface on both VMs.

b) Now, we will set the IP address on both virtual machines. The steps will be the same for both Ubuntu and Fedora. The IP addresses should be in the range of the “vboxnet0” network.

Run the following command on each machine.

a) Check the name of the connection

sudo nmcli con mod Wired\ connection\ 1 ipv4.addresses 192.168.56.10 / 24 ipv4.gateway 192.168.56.1 ipv4.method manual

sudo nmcli con down Wired\ connection\ 1

sudo nmcli con up Wired\ connection\ 1

a) Check the name of the connection

sudo nmcli con mod Wired\ connection\ 1 ipv4.addresses 192.168.56.11 / 24 ipv4.gateway 192.168.56.1 ipv4.method manual

sudo nmcli con down Wired\ connection\ 1

sudo nmcli con up Wired\ connection\ 1

Testing Network Connectivity

Now that we have configured the host-only networking, let us check if pinging is working between the VMs and host. We will ping each machine from the other:

1. Pinging from Ubuntu to Fedora and Host machine.

2. Pinging from Fedora to Ubuntu and Host machine.

3. Pinging from the Host machine to Fedora to Ubuntu.

Conclusion

We successfully configured Host-only networking between two virtual machines (VMs) in the VirtualBox. A good understanding of various features of the VirtualBox can help to create various configurations and scenarios for testing prior to deployment.

About the author

Ali Imran Nagori

Ali imran is a technical writer and Linux enthusiast who loves to write about Linux system administration and related technologies. You can connect with him on LinkedIn
.

Источник

Оцените статью
Adblock
detector