scripting host-only network creation using vboxmanage

Discussions related to using VirtualBox on Linux hosts.
Post Reply
ace01
Posts: 2
Joined: 2. Feb 2021, 15:34

scripting host-only network creation using vboxmanage

Post by ace01 »

I have a project that I built on Ubuntu 20.04 that scripts creation of CentOS 8 VMs using vboxmanage and kickstart. So far I've used bridged networking. That has the drawback that when you take the host (a laptop) to different networks the guest networking breaks. I would like to change to host-only and nat - and there is plenty of documentation on this. My plan would be to use vboxmanage to configure the host only network, and kickstart to populate /etc/sysconfig/network-scripts for each interface in the guest.

When I create one host-only network using Virtual Box, it appears pretty consistently to show up in the guest CentOS VM as "enps08". Since this is something that is scripted I'd like this to be deterministic. I don't see any way through vboxmanage to pick the interface name in the guest. And I don't see any documentation that says why VirtualBox selected "enps08" as the interface name. My concern is if someone ran the script on a machine with a different configuration, the guest interface could get named differently and break the kickstart configuration.

So that's a long way of asking: is it possible to force vboxmanage to use a specific interface name in the guest? Or if not - are the rules that vboxmanage follows to assign an interface name documented somewhere? Or if not - is there a way to configure the interface to automatically pick of the network settings from the device created by VirtualBox? All the documentation I've seen says to manually configure the interface in the guest once you start the machine...

Thanks
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: scripting host-only network creation using vboxmanage

Post by scottgus1 »

ace01 wrote:I don't see any way through vboxmanage to pick the interface name in the guest. And I don't see any documentation that says why VirtualBox selected "enps08" as the interface name.
I don't think there is, and I don't think it did. My understanding is that the OS names the network cards it finds, in physical or virtual PCs, and you'd have to configure the VM's OS to name the cards the way you want. FWIW other OS's call them 'eth0', 'eth1' etc.

Virtualbox, to the best of my knowledge, does not have a way to control the name the VM OS calls its Ethernet adapters.
ace01 wrote:is there a way to configure the interface to automatically pick of the network settings from the device created by VirtualBox? All the documentation I've seen says to manually configure the interface in the guest once you start the machine...
Bridged depends on the host's LAN to configure the IP address of the VM's adapter, because of the way Bridged works, see Virtualbox Networks: In Pictures: Bridged Adapter. Also, the default method of configuring an Ethernet adapter by an OS is through DHCP, which depends on the LAN. Per the linked tutorial, there are other things in the host or host LAN that might cause trouble for Bridged: incompatible Wi-Fi, host LAN with no DHCP server, no host LAN, etc. Presetting a static IP in the VM may also interfere in even a working Bridged adapter if the IP ranges are mismatched. You'd either need to let the VM's adapters be DHCP and self-configure, with suitable education for your users if they Bridge to Wi-Fi and have trouble, or go NAT/Host-Only.
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: scripting host-only network creation using vboxmanage

Post by fth0 »

Well, I can explain the origin of the interface names:

First of all, VirtualBox can emulate two chipsets: PIIX3 and ICH9 (see System > Motherboard > Chipset). Depending on the chipset, VirtualBox defines the layout of the virtual PCI busses that are provided to the guest. When using the PIIX3 chipset (default), the first four network adapters are devices 3, 8, 9 and 10 on PCI bus 0. On most modern Linux distributions, the network adapters are enumerated on the PCI busses and named enp0s3, enp0s8, enp0s9 and enp0s10 accordingly.

In consequence, the naming is indeed deterministic and predictable. This is also the reason why the old Linux naming scheme eth<n> is rarely used today: PCI bus device enumeration is not deterministic, and if you had multiple network adapters, any one could be found first and get named eth0.
ace01
Posts: 2
Joined: 2. Feb 2021, 15:34

Re: scripting host-only network creation using vboxmanage

Post by ace01 »

All - thank you for your replies - really helpful and I appreciate it!
Post Reply