Linux NFS
Ubuntu NFS version 4
- Single server scenario
In this example we will install server NFS running on Ubuntu 14.04 LTS and mount its exported file system to another Ubuntu host. This is the most common scenario where you will deploy a single server that allows one or more individual clients or networks to have access to one or more folders that can be mounted locally.
NFS server
One of requirments is that NFS server MUST have at least one static IP address that we can bind NFS service to. Next, be sure that the hostname (short and fully qualified) exist as an entry in your local hosts file.
vi /etc/hosts # add a line below, so the static ip has short and FQDN names 10.0.0.100 nfs-server nfs-server.example.com hostname -f #verify FQDN
Install packages
- nfs-common - common NFS client library
- nfs-kernel-server - NFS server demon/service
- rpcbind - tells other networked machines at what location to find a service
sudo apt-get install nfs-common nfs-kernel-server rpcbind
Create default RPCBIND config file, to explicitly call out that we are not passing any options to the daemon
vi /etc/default/rpcbind #crate a file with only line below OPTIONS=""
Allow other hosts on the network contact our server. Here all hosts on 10.0.0.0/24 network cat use portmap service and in turn NFS shares.
vi /etc/hosts.allow portmap: 10.0.0.
Enable idmapd, this is required for NFSv4
vi /etc/default/nfs-common #add a line below NEED_IDMAPD=YES
Configure idmapd, the file contains user mapping, you can leave it as it is
vi /etc/default/nfs-common
NFS Server - Export Configuration
Create NFS root directory
mkdir /srv/exports
Make the directory available using the access control list for filesystems which may be exported to NFS clients
vi /etc/exports #add the last line # Example for NFSv2 and NFSv3: # /srv/homes hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check) # Example for NFSv4: # /srv/nfs4 # gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check) # /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check) # /exports 10.0.0.0/255.255.255.0(rw,no_root_squash,no_subtree_check,crossmnt,fsid=0)
This simple file does a number of things. It defines the base directory of our share (in our case the previously created directory we called “/exports”), it provides read and write access to anyone on our allowed client network, it gives remote root/admin users full control over local root owned files (no_root_squash), don’t worry about the exported directory being an entire file system (no_subtree_check), allow subdirectories of the exported folder to be seen as subfolders (crossmnt) and finally assume that the volume share exported is a regular file system and not another share or special device (fsid=0).
Start NFS deamon and verify rpcbind status
sudo service nfs-kernel-server start sudo service rpcbind status
Configure Client
Install packages
sudo apt-get install nfs-common rpcbind
Mount NFS remote export
sudo mkdir /mnt/share sudo mount.nfs4 10.0.0.100:/ /mnt/share
Verify mount
mount | grep nfs 10.0.0.100:/ on /mnt/share type nfs4 (rw,addr=10.0.0.100,clientaddr=10.0.0.11)
Make the export permanent in fstab
vi /etc/fstab #add below 10.0.0.100:/ /mnt/share nfs4 rw 0 0