Configure NFS Server and Client


NFS server stands for Network File Sharing Server.

Basically in this, we create a machine as server, and select some folders, which we want to use from any machine in the same network.
So if you share a Folder named ‘Linux Servers’, we just need to mount it on the client’s pc, and he can use it any time, from his local machine. If you make an entry of this share in fstab, each time your machine boots, it will mount it automatically. So you can access that folder when you want.
So lets check out the steps to make configure NFS Server and Client. First we will create the NFS Server and then mount it on Client’s machine.

Server Side.

  1. Yum install nfs* -y
    Install all packages associated withnfs using yum or apt-get

    yum install nfs

    yum install nfs

     

  2. mkdir /srv/foldername
    Make the folder you want to share. If it already exists, skip this step.

    Create folder you want to share.

    Create folder you want to share.

     

  3. chmod 0755 /srv/foldername
    Change the permissions of the newly created folder or the folder you’re sharing. (in the next line, I am Just copying some files into that newly created folder.)

    Change permissions

    Change permissions.

     

  4. vim /etc/exports
    open the exports file. When you install NFS, it automatically creates an ‘exports’ file in ‘/etc’ In this exports file you describe your sharing folder and their permissions.

    open exports file, to enter sharing definations.

    open exports file, to enter sharing definations.

     

  5. /share folder1 (properties)
    /share folder2 (properties)
    This is the main part of your configuration. if you get this wrong, either there will be no sharing, or the shared folders wouldn’t open properly. The format to define sharing is :
    ‘path of folders to be shared’      IP/users (properties)
    If you need a whole subnet of IP to use that folder, or a particular IP, or a range of IP, you can define it here. If you want to share it with particular users on network, enter their hostnames.
    Properties
    ro = read only access
    rw= read and write access
    sync = will keep syncing the folder (If Shared folder is updated.)
    no_subtree_check : Increases the speed of transfer if large folder is shared.
    insecure : Tells the NFS server to use unprivileged ports (ports > 1024).
    Sample Output :

    Share definations

    Share definitions

    Here, I am allowing any IP between 192.168.0.0-192.168.0.255  to read or write my share.

  6. /etc/init.d/nfs restart
    Restart the service.

    Restart the service.

    Restart the service.

     

Client Side.

Lets look at the configuration on the client side. Make sure, you have installed ‘nfs-common’ package on client.

  1. showmount -e [ip address of server]
    ‘Show mount -e ‘ is used to check the mounting properties of a server. If you’re in the same network, and you can ping the server, it will show the shared folders and users/IP it is accessible to.
    Sample Output :
    Showmount -e [Sever IP]

    Showmount -e [Sever IP]

  2. mkdir /mnt/share1
    Create a new folder where you want the server’s shared folders to be mounted. Skip this, if you want to mount it on an already existing directory. Since you can see the server has 2 shared Directories, So create two new directories, with the same name, to avoid confusion.
    Sample Output :

    Create directory to mount the shares.

    Create directory to mount the shares.

     

  3. mount [source] [destination]
    Now you have the directories, where you need to mount those shared folders, so time to mount it.  My server’s Ip is 192.168.0.107, so ‘mount 192.168.0.107:/home’ is the source and ‘/mnt/nfs/home’ is the destination in my machine.
    Sample Output :

    mount

    mount

     

  4. Check if the shared folders are mounted.
    Sample Output :

    Checking shared folders

    Checking shared folders

    Checking shared folders

    Checking shared folders

If you need to add it in fstab :

192.168.0.107:/home  /mnt/nfs/home  nfs   rw   0,0

Leave a Reply