What we are currently using is the Bridged network and that works great out of the box but if we are using laptop which are always connecting on different network which results into IP always changing can make working with VM a little troublesome as you would need to change the config in hosts file with every IP change.
Another approach is to use two adapter instead one(bridged) to make VM connection - NAT and Host only Adapter.
One helps us keep a static IP address for the VBox and other gets us internet access.
VirtualBox > File > Host Network Manager > Create
- Please make sure to note the IP(default: 192.168.56.1) and uncheck the Enable DHCP
- Note the name of the host only network name(default: vboxnet0)
- Go in Network setting for your desired virtual box OS
- Adapter 1 > NAT
- Adapter 2 > Host- only Adapter , choose the name(vboxnet0)
- Power on your client OS
ifconfig -a
See the three network interfaces enp0s3 , enp0s8, lo
Here the enp0s8 isn’t configured and therefore has no IP address, lets configure that
sudo netplan generate
sudo nano /etc/netplan/anyfilename.yaml
Paste in the following into your file
network:
ethernets:
enp0s8:
dhcp4: no
dhcp6: no
addresses: [192.168.56.101/24]
gateway4: 255.255.255.0
enp0s3:
dhcp4: true
version: 2
Now we need to apply the settings
sudo netplan apply
Check for your IP for enp0s8 interface, which should be your static IP configured in yaml file above
ifconfig
Lets try to SSH from your host using this static IP
On your host(Mac/Windows)
sudo nano /etc/hosts
update the IP with the domain name used to connect the VM
192.168.56.101 yourgreatsite.com