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

Note: NFSv4 is the version used at the exam and doesn’t need any extra firewall configuration. However, beyond the exam objectives, if you plan to use NFSv3, you will also need to run these commands:

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

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

Note: You can test what is exported by the NFS server from a remote client with the command showmount -e nfsserver.example.com but you first need to stop Firewalld on the NFS server (or open the 111 udp and 20048 tcp ports on the NFS server).

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

45 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.

samuel.sappa
Member
samuel.sappa

Hi CertDepot,
In my nfs server, when executing the showmount -e localhost in server success (shared dir displayed), but when I execute on the client side error occurs no host to route, but the shared dir can be mounted by client both read and write can be done. Is this behavior normal on RHEL 7.0?

Thanks for your reply

Peatross
Member
Peatross

This doesn’t work for me unless on the server I do this in addition to nfs:

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

Lisenet
Member

Both rpc-bind and mountd services are only required by NFSv3, and can be skipped when setting up an NFSv4 server. Unless you are setting up an NFSv3 server, then your problem lies some other place.

Peatross
Member
Peatross

OK, with more troubleshooting it looks like it’s just the showmount command, and I see that’s already been addressed here.

So the firewall services mountd and rpc-bind allow port 111 and 20048 as it has already been identified.

Thanks

pomer
Member
pomer
Anyone having troubles installing file-server package? Other normal yum commands work, but not file-server. I guess I can try the required services find the individual packages for install. I haven’t seen a single comment about the file-server install issue under the comment section. I am using rhel 7.3 kernel version below. vmlinuz-3.10.0-514.21.1.el7.x86_64 Output from groupinstall error. [root@ipa ~]# yum groupinstall -y file-server Loaded plugins: langpacks, product-id, search-disabled-repos, subscription- : manager Maybe run: yum groups mark install (see man yum) No packages in any requested group available to install or update [root@ipa ~]# yum info nfs Loaded plugins: langpacks, product-id, search-disabled-repos,… Read more »
pomer
Member
pomer

Strangely, I get this error when testing the nfs mount from client. [root@server1 mnt]# showmount -e nfsserver.example.com
clnt_create: RPC: Port mapper failure – Unable to receive: errno 113 (No route to host)

However, it works when I disable the firewall on the server.

Strangely, when I check the mount point on the client and server, it is mounted and I can create or delete files on the client or server.

Based on the Redhat link, they state various reasons can cause this, mostly firewall block. Any thoughts?

Lisenet
Member

Be advised that the NFSv4 does not use the mountd daemon, therefore the showmount will not return information about version 4 mounts. However if you NFS server has NFSv3 enabled, then you can allow mountd and rpcbind traffic on the firewall, and use the showmount command.

pomer
Member
pomer
showmount fails with the error below. I can confirm the nfs mount works by creating and deleting files on the /mnt point on the client or server. It is just the showmount on the client that is not working. It does however work if I disable the firewall on the nfs server. One thing I noticed is there is no montd listening on port 20048 for version 4. Just version 3, not sure if that has to do with it. Any thoughts or assistance will be appreciated. [root@server1 mnt]# showmount -e nfsserver.example.com clnt_create: RPC: Port mapper failure – Unable to… Read more »
Lisenet
Member

To use the showmount command you need to allow mountd and rpcbind traffic on your firewall. Because NFSv4 does not use the mountd daemon, showmount will not return information about version 4 mounts.

samuel.sappa
Member
samuel.sappa

Just sharing, maybe someone can make sure about this, if my nfs-server is not available and if I reboot, my client get hangs (or maybe just take more time to reboot not sure about this)
after a search in the internet I got this https://access.redhat.com/solutions/28211
I’m using VirtualBox and rhel7.0
hope that’s help

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 default secure MariaDB database called maria with a user named muser with all privileges.

Follow me on Twitter

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 ...