In my case to use my RHEL virtual machine as development webserver, but be able to edit all files locally. I know there are other options, i.e. via sshfs and osxfuse, but NFS does support symlinks...
In your Virtual Box (application, not VM) configuration create a new Host-only network
IP4 Address: 192.168.56.1
IP4 Network Mask: 255.255.255.0
Enabled DHCP Server
Server Address: 192.168.56.100
Server Mask: 255.255.255.0
Lower Address Bound: 192.168.56.101
Upper Address Bound: 192.168.56.254
Stop VM and in its settings add a second interface (the first one should be NAT) with "Host-only adaptater" and "vboxnet0" (the one you just above)
Then you should have a new interface on your host:
ifconfig -a
vboxnet0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether 0a:00:27:00:00:00
inet 192.168.56.1 netmask 0xffffff00 broadcast 192.168.56.255
In your VM, create a config for the new interface by copying eth0
cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth1
vim /etc/sysconfig/network-scripts/ifcfg-eth1
Simply change the device name, it should look like this
DEVICE="eth1"
BOOTPROTO="dhcp"
NM_CONTROLLED="yes"
ONBOOT="yes"
Reboot the VM, the guest now have a new interface as well:
ifconfig -a
eth1 Link encap:Ethernet HWaddr 08:00:27:E8:41:72
inet addr:192.168.56.101 Bcast:192.168.56.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fee8:4172/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:367 errors:0 dropped:0 overruns:0 frame:0
TX packets:273 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:36792 (35.9 KiB) TX bytes:25230 (24.6 KiB)
For HTTPD to work with an NFS-mounted document root, you will probably need to disable SELinux on the guest:
vim /etc/selinux/config
insert or update:
SELINUX=disabled
Reboot the VM or call that one
setenforce 0
Now you probably need to install NFS in your VM
yum install nfs*
Start NFS service and add to autostart
service rpcbind start
service nfs start
/sbin/chkconfig --add rpcbind
/sbin/chkconfig --add nfs
Update VM firewall to allow all traffic to Host-only adapter
vim /etc/sysconfig/iptables
Insert the following rule after any eth0 rules or right before that rule: "-A INPUT -j DROP
":
-A INPUT -i eth1 -j ACCEPT
Restart the firewall
service iptables restart
You should be able to ping the host from vm and verce visa
ping 192.168.56.101 // from host to vm
ping 192.168.56.1 // from vm to host
Make the host's (OSX) directory/files accessable by setting up the NFS share Edit (and create) /etc/exports file
sudo vim /etc/exports
Add your folder to share, add as many as you like the ip at the end means that access is allowed from the vm only
/Users/<username>/Sites -alldirs -mapall=<username> 192.168.56.101
Restart NFS Server on host
sudo nfsd restart
Test it in your VM, if it works unmount it
mount -v 192.168.56.1:/Users/<username>/Sites /mnt
ls -lisa /mnt
umount /mnt
Add your mount config to /etc/fstab
to have it as a reboot-save shortcut
(I've added some performance optimizations for mount options)
192.168.56.1:/Users/<username>/Sites /var/www/vhosts nfs rsize=32768,wsize=32768,intr,noatime,rw,auto,rw 0 0
Then mount it, it will auto-mount on reboot
mount /var/www/vhosts
Lots of this what taken from https://tuleap.net/wiki/?group_id=101&pagename=Development+environment%2FVirtualBox