Difference between revisions of "Linux NFS"

From Ever changing code
Jump to navigation Jump to search
Line 14: Line 14:
One of requirments is that NFS server MUST have at least one static IP address that we can bind NFS service to.
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.
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
<source lang=bash>
10.0.0.100 nfs-server nfs-server.example.com
vi /etc/hosts    # add a line below, so the static ip has short and FQDN names
hostname -f  #verify FQDN
10.0.0.100 nfs-server nfs-server.example.com
hostname -f  #verify FQDN
</source>
 


Install packages
Install packages
Line 22: Line 25:
*nfs-kernel-server - NFS server demon/service
*nfs-kernel-server - NFS server demon/service
*rpcbind - tells other networked machines at what location to find a service
*rpcbind - tells other networked machines at what location to find a service
sudo apt-get install nfs-common nfs-kernel-server rpcbind
 
<source lang=bash>
sudo apt-get install nfs-common nfs-kernel-server rpcbind
</source>
 


Create default RPCBIND config file, to explicitly call out that we are not passing any options to the daemon
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
<source lang=bash>
OPTIONS=""
vi /etc/default/rpcbind    #crate a file with only line below
OPTIONS=""
</source>
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.
<source lang=bash>
vi /etc/hosts.allow
portmap: 10.0.0.
</source>


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
Enable idmapd, this is required for NFSv4
vi /etc/default/nfs-common  #add a line below
<source lang=bash>
NEED_IDMAPD=YES
vi /etc/default/nfs-common  #add a line below
NEED_IDMAPD=YES
</source>
 


Configure idmapd, the file contains user mapping, you can leave it as it is
Configure idmapd, the file contains user mapping, you can leave it as it is
vi /etc/default/nfs-common
<source lang=bash>
vi /etc/default/nfs-common
</source>


== NFS Server - Export Configuration ==
== NFS Server - Export Configuration ==

Revision as of 17:39, 13 March 2019

The Network File System (NFS) is a distributed file system protocol that was originally developed by Sun Microsystems. It allows a client computer to “mount” network folders from a server so that the resulting mount appears and behaves as a local file system to the client. NFS builds on the Open Network Computing Remote Procedure Call system and is currently an open standard that is defined as an RFC, which allows anyone to implement it.

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 base share 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)
ls /mnt/share    #should show NFS server files within this exported directory

Make the export permanent in fstab

vi /etc/fstab #add below
10.0.0.100:/    /mnt/share  nfs4    rw 0 0

References