How to install NFS Server in Centos 9 or Rocky Linux
In this article, we will talk about how to install NFS Server in Centos 9 or Rocky Linux 9. NFS stands for Network File System which is an Internet Standard Protocol and allows to share files in between various systems residing on the Local Area Network. In a typical setup an NFS Server is setup and shares (directories) are exported, systems running Linux or Windows can map these shared directories.
Installing NFS Server
In order to install NFS server in Centos 9 or Rocky Linux, we use dnf
package manager to install the required packages.
[root@server1 ~]# dnf install nfs-utils
you can get more information about what is provided in the nfs-utils
package by issuing following command
[root@server1 ~]# dnf info nfs-utils
...
Installed Packages
Name : nfs-utils
Epoch : 1
Version : 2.3.3
Release : 51.el8
Architecture : x86_64
Size : 1.5 M
Source : nfs-utils-2.3.3-51.el8.src.rpm
Repository : @System
From repo : baseos
Summary : NFS utilities and supporting clients and daemons for the kernel NFS server
URL : http://linux-nfs.org/
License : MIT and GPLv2 and GPLv2+ and BSD
Description : The nfs-utils package provides various utilities for use with NFS
: clients and servers.
Exporting the Share
The file /etc/exports
contains the information and control parameters about the shares which will be advertised to the client machines.
- Create a directory in the local filesystem of your Linux machine.
[root@server1 ~]# mkdir /nfs_share
- Open
/etc/exports
file in your favourite editor such as vi or nano.
[root@server1 ~]# vi /etc/exports
Insert the following line. Save and Exit the file.
/nfs_share 10.0.0.0/24(rw,sync,root_squash,no_subtree_check)
Let’s understand the configuration.
/nfs_share
is the local directory (on NFS Server) which will be advertised as a share to other systems
10.0.0.0/24
defines the network which is allowed to access this share. You can restrict the access to a share to
1. Single Host (10.0.0.11) | 2. Entire Network (10.0.0.0/24) |
3. Wildcard Machine names (*.itinfotech.ca) | 4. Host Groups |
- Share Options
rw | Allow both read and write requests on this NFS volume. |
sync | makes sure that changes have been saved to persistent store (disk). Opposite is async option, which means changes made to the files are written in memory before they are saved to persistent media. |
root_squash | this option makes sure that requests coming from uid 0 (root user) are mapped to anonymous uid such as nobody. In plain words, if the root user on client machine modifies any file, the ownership (user and group) will be shown as nobody:nobody instead of root:root |
no_subtree_check | subtree checking is a process which makes sure that if a subdirectory of the filesystem (folder within a folder) is exported, but the main filesystem (parent directory) is not, server must check the accessed files are in appropriate file system and also in the exported tree. no_subtree_check disables this checking |
There are various other options available. For the complete list of options, please refer to the man
page of exportfs
or use this link
Start the nfs-server
service or if the server was already running, export the shares.
[root@server1 ~]# systemctl start nfs-server.service
or
[root@server1 ~]# exportfs -av
exporting 10.0.0.0/24:/nfs_share
Client Setup
In the client Linux machine, install the nfs-utils package.
[root@server1 ~]# dnf install nfs-utils
Mounting the NFS Share temporarily
[root@client ~]# mount -t nfs <server_ip>:/nfs_share /share -vvv
Above command will mount
the nfs share named nfs_share
on client’s directory /share
Mounting the NFS Share permanently
open the /etc/fstab
file in your favourite editor and insert the following line
<server_ip>:/nfs_share /share nfs defaults 0 0
Don’t forget to replace server_ip with your NFS Server’s IP Address.
Save and exit the file. Issue the mount command.
[root@client ~]# mount -a
Verify the Share Exist in client machine
If the mount
command was successful, you can verify that share is available to use as shown below
[root@client ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
10.0.0.x:/nfs_share nfs4 37G 4.8G 32G 1% /share
tmpfs tmpfs 374M 0 374M 0% /run/user/0
[root@client share]# touch testfile
[root@client share]# ll
total 1
-rw-r--r-- 1 nobody nobody 0 Oct 8 00:40 testfile
Voilla! You have successfully created your own NFS Server. If you have any question or you are stuck feel free to comment in the comment section below.
1 Comment
Join the discussion and tell us your opinion.
wuoah this weblog iss fantastic i love studying yojr posts.
Stay up tthe good work! Yoou understand, mzny individuals are hunting around for this information, you
cann help them greatly.