Setup a NFS client on Red Hat / CentOS

nfs and smb

So this first thing that needs a bit of work on my end, starting on my RHCSA adventure, is to setup a NFS client.

It’s not too hard but there are a couple of things to consider and things like firewall and SELinux that can be easily overlooked.

The RHCSA exam focuses on the NFS client, but since we need a server to test, I need to set one up. This setup is NOT secure, it’s just for testing purposes. My server resides on IP 192.168.11.10 and my client on IP 192.168.11.11.

Let’s start out with NFS. On your server:

# yum install nfs-utils
# mkdir /nfs
# chmod 777 /nfs
# chown nfsnobody:nfsnobody /nfs
# vi /etc/exports

This installs the software, sets up your sharepoint and we’re creating the exports file which we’re whitelisting for our private IP address range:

/nfs	192.168.11.0/24(rw)

Fire up and check all these services:

# systemctl start nfs-idmapd nfs-server rpcbind rpc-statd
# systemctl status nfs-idmapd nfs-server rpcbind rpc-statd

Export and show mount(s):

# exportfs -a
# showmount -e localhost

To make it perfectly accessible from your client machine, open up these ports and reload the firewall:

# firewall-cmd --permanent --add-service=rpc-bind
# firewall-cmd --permanent --add-service=mountd
# firewall-cmd --permanent --add-service=nfs
# firewall-cmd --reload

On your client:

# yum install nfs-utils
# systemctl start rpc-bind
# mkdir /mnt/nfs

Check if you can see the export, mount it to your new directory and do a simple test:

# showmount -e 192.168.11.10
# mount -t nfs 192.168.11.10:/nfs /mnt/nfs
# cd /mnt/nfs/
# touch file{1..10}

Make it permanent in your /etc/fstab file by adding the below line:

192.168.11.10:/nfs    /mnt/nfs    nfs    defaults    0 0

Or when this does not work immediately:

192.168.11.10:/nfs    /mnt/nfs    nfs    defaults,user,exec,noauto,x-systemd.automount    0 0

This should do it. For automounting, autofs is also discussed in the study material, but I found it unnecessary complex.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.