Network File System (NFS) is one of the most used technology to share directories / folder from one server to another in UNIX based systems. As it is widely used technology in industries so every UNIX/Linux administrator should know how to setup NFS and share directories.
In today’s tutorial, we are going to tell you how to share directories through NFS from any RHEL 7 / CentOS 7 server to another Linux servers.
In this tutorial, we will use two Red hat Enterprise Linux 7 (RHEL 7) system, where one will work as server and other will work as a client where the shared directory will be mounted.
Steps to Share Directory through Network File System (NFS) on RHEL 7
1. First, you will have to install the NFS package on the server. Check if the package is already installed or not by below command.
# rpm -qa |grep -i nfs
If NFS packages are not installed, then install using your local YUM repository.
# yum install nfs-utils libnfsidmap
Once, packages are installed, you can again verify using the above command, it should look like below output.
[root@server ~]# rpm -qa |grep -i nfs libnfsidmap-0.25-12.el7.x86_64 nfs4-acl-tools-0.3.3-13.el7.x86_64 nfs-utils-1.3.0-0.21.e
2. Now, create directory to be shared through NFS. For this tutorial we will be creating folder called “nfs” on root mount point and will give it 777 permission, so that every one can read, write and execute. Will also set sticky bit for its protection.
# mkdir /nfs # chmod 1777 /nfs
3. Now, open configuration file of NFS i.e. /etc/exports and enter the details of client server along with the permission which needs to be given.
[root@server ~]# vi /etc/exports [root@server ~]# cat /etc/exports /nfs client11.example.com(rw,sync)
Here, we have used most common options, like rw and sync. This will give share read-write permission at client and real-time syncing.
Use below commands to export the directory and check what is currently being exported by the NFS server.
# exportfs –r # exportfs –v
4. Now start your NFS server, and enable it, so that it can withstand reboots. Use below commands for it.
# systemctl start nfs-server.service # systemctl enable nfs-server.service # systemctl start rpcbind # systemctl enable rpcbind
The Firewall also needs to be set properly for network file system (NFS) to work properly. Use below commands to add nfs service to firewall exceptions.
# firewall-cmd --permanent --add-service=nfs # firewall-cmd --reload
Below is the example of starting NFS service, enabling it and checking its status.
[root@server ~]# systemctl start nfs-server.service [root@server ~]# systemctl enable nfs-server.service ln -s '/usr/lib/systemd/system/nfs-server.service' '/etc/systemd/system/multi-user.target.wants/nfs-server.service' [root@server ~]# systemctl status nfs-server.service nfs-server.service - NFS server and services Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled) Active: active (exited) since Sat 2016-05-28 16:45:44 IST; 1min 21s ago Main PID: 5394 (code=exited, status=0/SUCCESS) [root@server ~]#
Once you have done above steps, you are good to proceed to client setup for network file system (NFS) sharing.
At Client Server
5. First of all, create a directory which will be mount point for the NFS share.
# mkdir /nfsshare
6. Now start rpcbind service and enable it.
# systemctl start rpcbind # systemctl enable rpcbind
Note: Client server does not require NFS services to be running.
7. Now, mount the NFS share on your client server with mount command.
# mount –t nfs server:/nfs /nfsshare
For permanent mounting make entry in /etc/fstab file like below and test by rebooting the server.
# vi /etc/fstab server.example.com:/nfs /nfsshare nfs defaults 0 0
This is how you can setup NFS server and share directories using it to the client.
This is a very basic setup with minimal options, we will be covering more NFS tutorials in detail in our next tutorial. You can expect tutorials on Kerberos enabled NFS sharing, troubleshooting NFS, sharing trough NFS version 4, etc. If you want to get more such tutorials then subscribe to our newsletter for free, like us on Facebook, follow us on Twitter and keep sharing or articles.