Networking in Virtual Box
So i started with a new journey in my career and on day one had some networking things got wrong in VMs and was not able to ssh.
What a pleasant start š , but it was a great learning experience so i am sharing it here.
My Use Case:
The architecture of the product I am currently working on is client - server based. So I need two VMs: vm-a (server/controller) & vm-b (client). Seems to be too simple but wait, so installation of agent on vm-b would be done from vm-a (via ssh). Now another twist in the story is to share the host machine(my laptop) VPN with both the VMs (because some repos are only accessible with company VPN).
I tried the above scenarios with following clients:
gnome-boxes
Since gnome-boxes is a very lightweight virtualization client it has minimal configuration options available (i didnāt dig much but definitely there should be some option) so could not proceed well on that tool.
virtmanger
With virt manager I didnāt have to struggle much, by default it created/added a network interface with NAT config and nothing much to do.
virutal box
Virtual box by default created/added the default NAT network interface but I was only sharing the host machine network. So I was able to share my host machine VPN session inside both the VMs but not able to ssh into VMs(from host) and between VMs(vm-a & vm-b). It was not an issue but a configuration missing.
To satisfy my use case i needed two virtual network interfaces/adapter to be enabled on both the VMs
1. NAT (default interface)
2. Host-only Adapter
Step 1:
First I need to check if the host-only interface is added into Host Network Manager(for me it was not there so I had to add it manually).
File > Host Network Manager > create( if no entry of any interface found)
After adding interface it should look like this
Step 2:
Now you need to add this interface to VM settings
VM settings > Network > Adapter 2
- Enable/tick āEnable Network Adapterā checkbox
- Choose āHost-only Adapterā in Attached to menu
- Name should be automatically selected if not please do add it manually.
I am using the RHEL-9 image in the VM, so one should make sure if you are able to see two networks enabled in the VM when you boot.
You can see two IPās assigned to your machine.
- Interface
enp0s3
ip:10.0.2.15
is the NAT interface which shares host networks. - Interface
enp0s8
ip:192.18.56.102
is host only interface which is a local network to ssh into VM from host and/or between VMs.
I am not denying the fact that there could be more options to get this thing done.
This was my day one adventure.
Happy Networking :)