NFS is a protocol for sharing storage over a network. It has been supported by unix since day . (dot) and I believe now windows even supports it!
In order to share a directory on ubuntu, first install the prerequisites:
sudo apt-get install nfs-kernel-server nfs-common portmap
Then modify the file /etc/exports
and specify the folders that are going to be made available to clients, for example:
/media/share 127.0.0.0/24(rw,sync,no_subtree_check,insecure,all_squash,anonuid=1000,anongid=1000)
What does all that mean!??
/media/share
is a directory to export. By default, all directories contained within/media/share
will also be available127.0.0.0/24
is the address/netmask of devices that have access to the shares. If you do not care who has access, the wildcard*
can be used- Contained within the parenthesis is a series of options:
rw
– Allow both read and write operations. To allow only read access, usero
insteadsync
– Ensures that changes to files are committed to stable storage, as opposed toasync
in which a crash can lead to unclean server state and cause data to be lost or corruptedno_subtree_check
– disables the subtree checking, this is recommended for home directories and others that are mountedrw
. This is the defaultinsecure
– Allow non-default ports for accessing the NFS server. By default, port requests are expected to be on ports less than1024
(usually by theroot
user)all_squash
– Ignore the uid/gid of the connected user (map it to the anonymous user)anonuid
– Set the uid of the anonymous user. This andanongid
option is useful for clients where you might want all the requests to appear to be from a single useranongid
– Set the gid of the anonymous user
Additional examples can be found in the exports(5)
man page.
Once /etc/exports
has been modified, restart the NFS server and re-export:
sudo /etc/init.d/nfs-kernel-server restart sudo exportfs -a
In order to see if the exports are working correctly, run the showmount utility:
showmount -e localhost
Example output:
Export list for localhost: /media/share 127.0.0.0/24
To mount this new share, run the mount command:
sudo mount localhost:/media/share /mnt
Ensure that the mount is successful, and it can be viewed by either:
mount df -h