This creates a dedicated network between the host and guest, allowing you to SSH and use other network services without the need of an external router.
- In VirtualBox, edit VM settings and add a second host-only network adapter
- Log into the guest VM
- Run
ifconfig, note the new adapter's interface name (likeenp0s8) - Run
nmtuiEdit a connection>Add>Ethernet- Profile name:
Host-only Adapter - Device:
enp0s8(interface output fromifconfig) - IPv4 configuration:
- Addresses:
192.168.56.100/24
- Addresses:
- Save new connection
- Activate the new connection
- Ensure no other connections appear under the Host-only Network adapter
- Allow all external connections on the 192.168 subnet:
firewall-cmd --permanent --add-rich-rule 'rule family="ipv4" source address="192.168.0.0/16" accept'
- VM should now be accessible from the host via
192.168.56.100
This allows you to edit and use files on the host from the guest.
- Shutdown VM
- Add shared folder to VM
- VM >
Settings...>Shared Folders - Add a new shared folder under `Machine Folders
Folder Path: Specify the host path to shareFolder Name: Choose a simple identifier, e.g. "project" or "shared"Read-only: noAuto-mount: noMake Permanent: yes- Save changes
- VM >
- Add CD-ROM device to VM
- VM >
Settings...>Storage Add IDE Controllerif one doesn't already exist- Under the IDE controller, add an optical drive, choose
Leave Empty - Save changes
- VM >
- Install kernel modules for shared folders
- Boot VM
- Once VM is booted, from the menu, choose
Devices>Insert Guest Additions CD image... mount /dev/cdrom /mnt/cdrom/mnt/cdrom/VBoxLinuxAdditions.run- The installer might complain about not having kernel headers available
- If so:
yum install kernel-devel kernel-devel-3.10.0-693.2.2.el7.x86_64 - Re-run installer
- Add shared folder mount to
/etc/fstab:project /srv/www/project vboxsf rw,uid=0,gid=0,fmode=0777,dmode=0777 0 0projectis the simple identifier you used when adding a shared folder in VirtualBox settings
- Reboot, shared folder should be available under
/srv/www/project
This allows you to create symlinks in a shared folder on the guest. This must be done for each shared folder you have.
- See this answer for details
- Important: Shutdown VM and the VirtualBox GUI
- On the host
VBoxManage setextradata VirtualMachineName VBoxInternal2/SharedFoldersEnableSymlinksCreate/project 1VBoxManage getextradata VirtualMachineName enumerateVirtualMachineNameis the name of your virtual machine as seen in VirtualBoxprojectis the name of your shared folder in the VM's Shared Folders settings
- Boot VM
- On the guest, create a test symlink
cd /srv/www/project && ln -s . testrm test