Wednesday, May 15, 2024

VirtualBox Virtual Networking between Guests

 Host: Windows 11

Guest 1: NixOS (Linux)

Guest 2: FreeBSD (Unix)

Reason: Needed to migrate files from NixOS to a fresh install of FreeBSD. Unfortunately, BSD was not

detecting the host's Shared Folder, so I decided to copy the file(s) the good old Unix way, SCP. As VirtualBox siloes each guest into its own network, using the default NAT setting, they do not communicate with the Host or the other Guests. Since VBox handles the networking, there are two options, either using Bridged or Internal Networking. This posts uses the Internal Networking option.

The setup for the guests are as follows; each guest will have the primary adapter (Adapter 1) set to the default NAT, and the secondary adapter (Adapter 2) set to Internal Network

Fig 1: NixOS Network Adapter 1 settings

Fig 2: NixOS Network Adapter 2 settings

Fig 3: FreeBSD Network Adapter 1 settings

Fig 4: NixOS Network Adapter 2 settings

Boot the guest VMs and check their assigned IP addresses, labelled as `inet` using `ifconfig`

 On both guests, Adapter 2 settings will be incremented by one(1), example, BSD will show `em0` as the primary and `em1` as the secondary. NixOS will auto-assign the inet and netmask, however, BSD may not. In that case, follow these steps.

  1. Determine the state of the interface with `ifconfig -d`. If the device `em1` appears as output, the interface is down. Alternatively, `ifconfig -u` will show all active network interfaces.
    1. If the interface is down, activate it (turn it on) with `ifconfig em1 up`
  2. Even though `em1` is now active, it may not have an IP address assigned. Even using DHCP, it may not have been leased an address. Either way, provide a static address with the following command
    1. `ifconfig em1 inet <ip.add.re.ss> netmask <sub.net.ma.sk>` the IP address and subnet mask were copied from Guest 1, just incremented the IP by 1. Example, Guest 1 is aaa.bbb.ccc.193, then set Guest 2 to aaa.bbb.ccc.194, keeping the subnet mask the same.
    2. Test your changes with `ifconfig em1`, and by pinging Guest 1. If your settings were accurate, then you should get a response.
  3. Ensure `sshd` is running on Guest 2. If it is, then log into Guest 1, and test it by SSHing to Guest 2. 
  4. Once logged in, disconnect and then use SCP to copy the files from Guest 1: `scp /guest1/local/file <username@guest2:/target/dir`

No comments:

Post a Comment