0

I want to assign a static IP to ubuntu 18.04 VM in a virtualbox. I had bridged adopter for adapter 1 and i tried below steps to set static IP,

  1. In the virtual box Host Network Managementt setting, disabled DHCP.
  2. Made Adapter 1 attaching to option as HostOnly Adapter
  3. Started VM and inside VM, opened /etc/netplan/01-netcfg.yaml and made below modifications
network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      addresses: [10.110.249.15/24]
      gateway4: 10.110.249.1
      nameservers:
        addresses: [10.110.249.1, 8.8.8.8]
      dhcp4: no

My requirement is to access all the hosts in 10.110.249 network and with the above steps i was not able to do that.

How to fix this? Should i just change the adapter 1 setting to bridged adapter and start the VM?

Also in bridged adapter mode, if the host machine where virtual box is installed is accessible to other hosts, will the ubuntu VM also be accessible?

0

If you wish to access the Virtual Machines from one another you can simply do that assigning the same network adapter to all of them. However if you also wish to access the host OS hosting all the VMs then you would need to set up network adapter in "bridged mode".

I will try to explain the concept. By assuming/creating different scenarios.

1. You have a system connected to your home router

When you connect your system with your router either via a WiFi or an Ethernet cable.
What your router does is, it assigns your system an IP address, this IP address is considered to be private IP address. You are provided a single public IP address by your ISP ( Internet Service Provider ). This public IP address is converted to your private IP using NAT (Network address translator) by your router.

And the private IP address which are assigned to your devices which are connected to your router are decided by DHCP ( Dynamic Host Configuration Protocol ). It automatically creates IP address to be assigned. Hence this can be understood as a sort of Dynamic IP address mapping or assignment. Now you can also assign a static IP address to your devices by managing your router settings.

The difference b/w dynamic and static IP address is that if you disconnect a device and reconnect it later, it may or may not have same IP address as it had when it was previously connected in case of dynamic IP address however in static IP address it will always have same IP address irrespective of how many times you disconnect and reconnect it.

P.S
All the hosts connected to your router can talk or communicate with each other irrespective the assignment is done static or dynamic because to communicate you need to know the IP address. To check this you can try to ping your mobile or any other device in your LAN (Local area network) with your PC.

2. You create a VM in your PC

Now that you have created a virtual machine in your PC by using Virtual Box. The IP address assigned to your VM is handled by the network adapter of Virtual Box. In essence you could say that your host OS is now working as a router for your Virtual Machines, and the management of those IP address is done by Virtual Box.
Now Virtual box comes with a setting of NAT-network and bridged mode.

NAT-network mode

This is something like the PC to router ideology that I explained earlier. Your host OS running Virtual Box acts as a router to your VM. Now in this case all the VM can communicate with each other if they are using the same network adapter however they can't communicate with the host OS running the Virtual Box.

Bridged mode

In this case the Virtual Box aligns all the Virtual Machines parallel to your host OS. This means the IP address assignment for all your VMs is now done by the router from which you are getting your internet connection to your host OS running Virtual Box. Now all your VMs can communicate with each other including your host OS.


Conclusion

Now I believe you have knowledge for what should be done for your problem and you can apply the correct solution to it. To make the VMs communicate to each other you do not need to assign a static IP address. However if you wish to make some sort of server with static IP address then you could assign your Ubuntu a static IP address from Virtual Box settings. You can read how to do that from here
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.