RHEL7: Provide NFS network shares to specific clients.

Share this link

Note: This is an RHCE 7 exam objective.

In this tutorial, the NFS server is called nfsserver.example.com and the NFS client nfsclient.example.com.

NFS Server Configuration

Install the file-server package group:

# yum groupinstall -y file-server

Add a new service to the firewall:

# firewall-cmd --permanent --add-service=nfs
success

Reload the firewall configuration:

# firewall-cmd --reload
success

Activate the NFS services at boot:

# systemctl enable rpcbind nfs-server

Note: The nfs-idmap/nfs-idmapd (changes happened with RHEL 7.1) and nfs-lock services are automatically started by the nfs-server service. nfs-idmap/nfs-idmapd is required by NFSv4 but doesn’t allow you any UID/GID mismatches between clients and server. It is only used when setting ACL by names or to display user/group names.
All permission checks are still done with the UID/GID used by the server (see this thread about nfs-idmap for more details).

Start the NFS services:

# systemctl start rpcbind nfs-server

Note1: By default, 8 NFS threads are used (RPCNFSDCOUNT=8 in the /etc/sysconfig/nfs file). This should be increased in a production environment to at least 32 (source: http://initrd.org/wiki/NFS_Setup).
Note2: Optionally, to enable SELinux Labeled NFS Support, edit the /etc/sysconfig/nfs file and paste the following line (source): RPCNFSDARGS=”-V 4.2″

Create directories to export and assign access rights:

# mkdir -p /home/tools
# chmod 0777 /home/tools
# mkdir -p /home/guests
# chmod 0777 /home/guests

Assign the correct SELinux contexts to the new directories:

# yum install -y setroubleshoot-server
# semanage fcontext -a -t public_content_rw_t "/home/tools(/.*)?"
# semanage fcontext -a -t public_content_rw_t "/home/guests(/.*)?"
# restorecon -R /home/tools
# restorecon -R /home/guests

Note: The public_content_rw_t context is not the only available, you can also use the public_content_ro_t (only read-only) or nfs_t (more limited) contexts according to your needs.

Check the SELinux booleans used for NFS:

# semanage boolean -l | egrep "nfs|SELinux"
SELinux boolean                State  Default Description
xen_use_nfs                    (off  ,  off)  Allow xen to use nfs
virt_use_nfs                   (off  ,  off)  Allow virt to use nfs
mpd_use_nfs                    (off  ,  off)  Allow mpd to use nfs
nfsd_anon_write                (off  ,  off)  Allow nfsd to anon write
ksmtuned_use_nfs               (off  ,  off)  Allow ksmtuned to use nfs
git_system_use_nfs             (off  ,  off)  Allow git to system use nfs
virt_sandbox_use_nfs           (off  ,  off)  Allow virt to sandbox use nfs
logrotate_use_nfs              (off  ,  off)  Allow logrotate to use nfs
git_cgi_use_nfs                (off  ,  off)  Allow git to cgi use nfs
cobbler_use_nfs                (off  ,  off)  Allow cobbler to use nfs
httpd_use_nfs                  (off  ,  off)  Allow httpd to use nfs
sge_use_nfs                    (off  ,  off)  Allow sge to use nfs
ftpd_use_nfs                   (off  ,  off)  Allow ftpd to use nfs
sanlock_use_nfs                (off  ,  off)  Allow sanlock to use nfs
samba_share_nfs                (off  ,  off)  Allow samba to share nfs
openshift_use_nfs              (off  ,  off)  Allow openshift to use nfs
polipo_use_nfs                 (off  ,  off)  Allow polipo to use nfs
use_nfs_home_dirs              (off  ,  off)  Allow use to nfs home dirs
nfs_export_all_rw              (on   ,   on)  Allow nfs to export all rw
nfs_export_all_ro              (on   ,   on)  Allow nfs to export all ro

Note1: The State column respectively shows the current boolean configuration and the Default column the permanent boolean configuration.
Note2: Here we are interested in the nfs_export_all_rw, nfs_export_all_ro and potentially use_nfs_home_dirs booleans.
Note3: The nfs_export_all_ro boolean allows files to be shared through NFS in read-only mode but doesn’t restrict them from being used in read-write mode. It’s the role of the nfs_export_all_rw boolean to allow read-write mode.

If necessary, assign the correct setting to the SELinux booleans:

# setsebool -P nfs_export_all_rw on
# setsebool -P nfs_export_all_ro on
# setsebool -P use_nfs_home_dirs on

Edit the /etc/exports file and add the following lines with the name (or IP address) of the client(s):

/home/tools nfsclient.example.com(rw,no_root_squash)
/home/guests nfsclient.example.com(rw,no_root_squash)

Note: Please, don’t put any space before the opening parenthesis, this would completely change the meaning of the line!

Export the directories:

# exportfs -avr
exporting nfsclient.example.com:/home/guests
exporting nfsclient.example.com:/home/tools
# systemctl restart nfs-server

Note: This last command shouldn’t be necessary in the future. But, for the time being, it avoids rebooting.

Check your configuration:

# showmount -e localhost
Export list for localhost:
/home/guests nfsclient.example.com
/home/tools  nfsclient.example.com

NFS Client Configuration

On the client side, the commands are:

# yum install -y nfs-utils
# mount -t nfs nfsserver.example.com:/home/tools /mnt

Additional Resources

The GeekDiary website provides a tutorial about Configuring a NFS server and NFS client.

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

Leave a Reply

33 Comments on "RHEL7: Provide NFS network shares to specific clients."

Notify of
Sort by:   newest | oldest
kostyrev
Member
kostyrev

Following this manual
[root@rhel7-client ~]# mount -t nfs rhel7-server.local:/home/tools /mnt/
[root@rhel7-client ~]# ll /mnt/
total 0
[root@rhel7-client ~]# echo 123 > /mnt/file1
hangs for too long
why?

jerky_rs
Member
jerky_rs

be prepared to open 111 udp/tcp and whatever port you assign to Mountd 20048 udp/tcp (as configured in /etc/sysconfig/nfs) as “showmount -e servername” should work by doing “ls /net/servername” if you have automount turned on. Although NFSv4 does not actually require these ports for operation “showmount” does.

Sam
Member
Sam

After a little search … grep.. these two services are located in the firewall default xml.

20048 udp/tcp service is know as mountd
111 udp/tcp service is know as rpcbind

firewall-cmd –add-service=mountd –permanent
firewall-cmd –add-service=rpc-bind –permanent

michaels
Member
michaels

From the RedHat webpage:

Enable the services at boot time

# systemctl enable nfs-server
# systemctl enable rpcbind
# systemctl enable nfs-lock <– In RHEL7.1 (nfs-utils-1.3.0-8.el7) this does not work (No such file or directory). it does not need to be enabled since rpc-statd.service is static.
# systemctl enable nfs-idmap <– In RHEL7.1 (nfs-utils-1.3.0-8.el7) this does not work (No such file or directory). it does not need to be enabled since nfs-idmapd.service is static.

mabhatter
Member
mabhatter

two of the commands at the start of the tutorial are broken.

# systemctl enable nfs-server
# systemctl enable nfs-lock

both fail with the mysterious error command. The cause seems to be a change to how links are made in the packages and systemctl doesn’t work with links to files…. at least the short version from Googling. The services do actually start with the start command listed, but it kind of breaks the tutorial. Also, a comment to how we can check the systemctl status for these would be helpful.

Thanks for the great tutorials!!!

SAGAR
Member

If it takes too long or seems like a hang while creating files or folders in NFS shares then the reason could be the ownership issue. Try changing the ownership of the nfsshare at server to nfsnobody as :
chown -R nfsnobody:nfsnobody /nfsshare
chmod -R g+rxws /nfsshare

Now try creating…

cdz
Member
cdz

you have configured to /etc/export for specific clients (“client1”, “client2”), but later in output of “showmount -e localhost” we see asterisks (*). Shouldn’t “client1” and “client2” be there?

langtu1511
Member
langtu1511

Hi,

When I tried to start nfs-lock and nfs-idmap services, there are problems.
[root@server1 ~]# systemctl enable nfs-lock
Failed to issue method call: No such file or directory
[root@server1 ~]# systemctl enable nfs-idmap
Failed to issue method call: No such file or directory

But the nfs service was working well.

I don’t know why there is nfs-lock and nfs-idmap services (I cant start/stop) but I can’t enable them.

dan
Member
dan

Why did you decide to use no_root_squash option for the /home/guests share? I imagine it should never be accessed by root on client…

Ze
Member
Ze

When using automount for ldap user’s home directories, do those home directories need to exist on the servers side before we log into the client as the ldap user? Or will the home directory automatically be created on the nfs share when ldapuser logs on the client side?

hunter86_bg
Member

I thought that we should use NFS v4 – which is the only version that supports kerberos , if I’m not wrong.
Am I with a wrong impression ?

Lisenet
Member

On RHEL 7, by default, mount will use NFSv4 with “mount -t nfs”. If the server does not support NFSv4, the client will automatically step down to a version supported by the server.

hunter86_bg
Member

Yes, but if you want to enable NFSv4 only is different than NFSv3 + NFSv4. So, if on the exam nothing is mentioned about the version, should I assume NFSv4 only?

Lisenet
Member

The opposite – you shouldn’t assume things on the exam. If it’s not mentioned, then use the settings that come with the OS.

hunter86_bg
Member

It seems with this guide it provides both ver3 and ver4 NFS server 🙂
The only think I have installed is:”nfs-utils nfs4-acl-tools”

Lisenet
Member

Yes.

hunter86_bg
Member

I was playing with NFS and I found out in the web that it is possible to limit the nfs version by editing “/etc/sysconfig/nfs” and adding the following:
RPCNFSDCOUNT=” –no-nfs-version ”
Of course a restart of the server is needed.

wpDiscuz

RHCSA7: Task of the day

Allowed time: 8 minutes.
Find all files bigger than 100MB and write their names into the /root/results.txt file.

RHCE7: Task of the day

Allowed time: 10 minutes.
Set up a caching-only DNS server.

Poll for favorite RHEL 7 book

What is your favorite RHEL 7 book to prepare RHCSA & RHCE exams?

View Results

Loading ... Loading ...

Poll for most difficult RHCSA 7 topic

What do you think is the most difficult RHCSA 7 topic?

View Results

Loading ... Loading ...

Poll for most difficult RHCE 7 topic

What do you think is the most difficult RHCE 7 topic?

View Results

Loading ... Loading ...