24/7/365 Support

Working with NFS in CentOS

Before a client computer can use file system exports shared by an NFS server, it has to be configured to correctly access this system. Here in this process, we will show you how to set things up and work with NFS on the client machine.

To Start With: What Do You Need?

To complete this process, you will require a working installation of the CentOS 7 operating system with root privileges, a console-based text editor of your choice, and a connection to the Internet in order to facilitate the download of additional packages. It is expected that you have already followed the Installing and configuring NFS process and have set up an NFS server, such as in this example. It is expected that all the clients can ping each other and are connected to the NFS server, and will be using a static IP address (see the process, Building a static network connection, in Configuring the System). In our example, the NFS server is running with the IP 192.168.1.10 and two clients with the IPs

192.168.1.11 and 192.168.1.12.

The Process

On our client systems, we also need the same NFS software package, and a similar configuration to the one on the server, in order to establish a communication between them:

  1. To begin, log in on your client as root, and apply the exact same steps as in the Installing and configuring NFS process until the end of step 3. Skip step 4 because no firewalld service must be opened. Then, instead of step 5, use the following commands, which will not start and enable the nfs-server, but only the rpcbind service instead:
    systemctl start rpcbind
    systemctl enable rpcbind
  2. Stop there and do not apply anything else from the original process. To test the connection to our NFS server, use the following command:
     showmount -e myServer.example.com
  3. Now, to test if attaching the NFS exports works you can do so manually using a new user, john. This needs to be added to the nfs-share group first in the following way so that we can write on our share:
    groupadd -g 50000 nfs-share;useradd john;passwd john;usermod -G nfs
    share john
    mount -t nfs4 myServer.example.com:/srv/nfs-data /mnt
    su -john;touch /mnt/testfile.txt
  4. If the creation of the file in the shared directory works, you can put the import in the fstab file so that it will be automatically mounted on system boot:
    vi /etc/fstab
  5. Append the following line:
    myServer.example.com:/srv/nfs-data /mnt nfs defaults 0 0
  6. Finally, to remount everything from fstab, type the following:
    mount -a

How Does It Work?

In this process, we showed you how easy it is to use some shared file system exports from an existing NFSv4 server.

So, what did we learn from this experience?

As you have seen, to set up an NFS client, you need a very similar setup to the one on the NFS server itself, with the exception of starting the rpcbind service instead of nfsserver (which, as the name implies, is only needed for the server side). The rpcbind service is a port mapper and is used for Remote Procedure Calls (RPC), which is a communication standard needed for NFS to work. Another very crucial step in the configuration that you should remember was setting up the domain name in the /etc/idmapd.conf file. We will have to use the same base domain name as on the server (example.com) in order to make the NFSv4 communication between server and client work. After having started and enabled the rpcbind service, we could then mount the NFS share to a local directory, either using the mount command (with -t type nfs4) directly or via the fstab file. Remember, that every system user who wants proper read/write/execute permissions to a share needs the same permissions on the NFS server; in our example, we manage correct permissions on an identical GID level. We used the default options to mount the share; if you need different or advanced options, please refer to man fstab. In order to apply changes to the fstab file, perform mount -a to remount everything from that file.

 

Help Category:

What Our Clients Say