{"id":9938,"date":"2021-08-02T23:25:40","date_gmt":"2021-08-02T20:25:40","guid":{"rendered":"https:\/\/kifarunix.com\/?p=9938"},"modified":"2024-03-18T19:11:23","modified_gmt":"2024-03-18T16:11:23","slug":"install-and-configure-nfs-server-on-rocky-linux-8","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-and-configure-nfs-server-on-rocky-linux-8\/","title":{"rendered":"Install and Configure NFS Server on Rocky Linux 8"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"598\" height=\"297\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/08\/nfs.png\" alt=\"Install and Configure NFS Server on Rocky Linux 8\" class=\"wp-image-9951\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/08\/nfs.png 598w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/08\/nfs-150x74.png 150w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/08\/nfs-300x149.png 300w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/08\/nfs-324x160.png 324w\" sizes=\"(max-width: 598px) 100vw, 598px\" \/><\/figure><\/div>\n\n\n<p>In this tutorial, we will learn how to Install and Configure <a href=\"https:\/\/linux.die.net\/man\/5\/nfs\" target=\"_blank\" rel=\"noreferrer noopener\">NFS<\/a> server on Rocky Linux 8. Network File system (NFS)&nbsp;is a commonly used file-based storage system that&nbsp;allows remote systems&nbsp;to access files over a computer network&nbsp;and interact with them as if they were locally mounted. This enables system Administrators to group resources onto centralized servers on a network for easy sharing.<\/p>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li><a href=\"#installing-nfs-server-on-rocky-linux-8\">Installing NFS server on Rocky Linux 8<\/a><ul><li><a href=\"#install-nfs-packages\">Install NFS Packages<\/a><\/li><li><a href=\"#configure-nfs-server-on-rocky-linux-8\">Configure NFS Server on Rocky Linux 8<\/a><ul><li><a href=\"#update-hosts-dns-domain-name\">Update host&#8217;s DNS domain name<\/a><\/li><li><a href=\"#define-nfs-server-shares\">Define NFS Server Shares<\/a><\/li><li><a href=\"#allow-nfs-service-on-firewalld\">Allow NFS Service on Firewalld<\/a><\/li><li><a href=\"#running-nfs-service\">Running NFS Service<\/a><\/li><\/ul><\/li><li><a href=\"#configure-nfs-client\">Configure NFS client<\/a><ul><li><a href=\"#install-nfs-packages-1\">Install NFS Packages<\/a><\/li><li><a href=\"#discover-nfs-server-shares\">Discover NFS Server Shares<\/a><\/li><\/ul><\/li><\/ul><\/li><li><a href=\"#configuring-automounting\">Configuring Automounting<\/a><ul><li><a href=\"#automounting-with-fstab\">Automounting with FSTAB<\/a><\/li><li><a href=\"#automounting-with-autofs\">Automounting with Autofs<\/a><\/li><li><a href=\"#other-tutorials\">Other Tutorials<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"installing-nfs-server-on-rocky-linux-8\">Installing NFS server on Rocky Linux 8<\/h2>\n\n\n\n<p>To Configure NFS server, we will be using two Rocky Linux 8 servers;<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>NFS server:\n<ul class=\"wp-block-list\">\n<li>nfs.kifarunix-demo.com<\/li>\n\n\n\n<li>192.168.60.19<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>NFS client:\n<ul class=\"wp-block-list\">\n<li>nfsclient.kifarunix-demo.com<\/li>\n\n\n\n<li>192.168.60.23<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-nfs-packages\">Install NFS Packages<\/h3>\n\n\n\n<p>Before proceeding with the configuration, you need to&nbsp;<strong>install NFS packages<\/strong>&nbsp;by running the command below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>dnf install nfs-utils -y<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"configure-nfs-server-on-rocky-linux-8\">Configure NFS Server on Rocky Linux 8<\/h3>\n\n\n\n<p>Once the NFS packages are installed, proceed to configure it.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"update-hosts-dns-domain-name\">Update host&#8217;s DNS domain name<\/h4>\n\n\n\n<p>NFS server domain name can be updated by editing the file,&nbsp;<strong>\/etc\/idmapd.conf<\/strong>, and uncommenting and changing the line below accordingly.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#Domain = local.domain.edu<\/code><\/pre>\n\n\n\n<p>You can simply run the command below to uncomment and change the domain name.<\/p>\n\n\n\n<p><strong>Replace the domain name, <em><code>kifarunix-demo.com<\/code><\/em>, with your server&#8217;s domain name.<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sed -i '\/^#Domain\/s\/^#\/\/;\/Domain = \/s\/=.*\/= kifarunix-demo.com\/' \/etc\/idmapd.conf<\/pre>\n\n\n\n<p><strong>idmapd <\/strong>is the NFSv4 ID name mapping daemon which provides functionality to the NFSv4 kernel client and server, to which it communicates via upcalls, by translating user and group IDs to names, and vice versa.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"define-nfs-server-shares\">Define NFS Server Shares<\/h4>\n\n\n\n<p>The file <strong><code>\/etc\/exports<\/code><\/strong> contains a table of local physical file systems on an NFS server that are accessible to NFS clients.<\/p>\n\n\n\n<p>You need to edit this file&nbsp;and add&nbsp;<em>file system<\/em>&nbsp;or&nbsp;<em>directory<\/em>&nbsp;to be exported to client and specify the options to apply to those shares.<\/p>\n\n\n\n<p>NB: Each entry for an exported file system has the following structure:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>export host(options)<\/code><\/pre>\n\n\n\n<p>where:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>export<\/strong>&nbsp;is the file system or directory to be mounted on remote host<\/li>\n\n\n\n<li><strong>host<\/strong>&nbsp;is the remote host\/client to be allowed to access a shared folder. The host can be defined as:\n<ul class=\"wp-block-list\">\n<li><strong>single host<\/strong>: You may specify a host either by an abbreviated name recognized be the resolver, the fully qualified domain name, an IPv4 address, or an IPv6 address.<\/li>\n\n\n\n<li><strong>IP networks<\/strong>: You can define hosts by specifying an IP address and netmask pair as address\/netmask.<\/li>\n\n\n\n<li><strong>wildcards<\/strong>: Machine names may contain the wildcard characters * and ?, or may contain character class lists within [square brackets]. This can be used to make the exports file more compact; for instance, *.cs.foo.edu matches all hosts in the domain cs.foo.edu. As these characters also match the dots in a domain name, the given pattern will also match all hosts within any subdomain of cs.foo.edu.<\/li>\n\n\n\n<li><strong>netgroups<\/strong>: NIS netgroups may be given as @group. Only the host part of each netgroup members is consider in checking for membership. Empty host parts or those containing a single dash (-) are ignored.<\/li>\n\n\n\n<li><strong>anonymous<\/strong>: This is specified by a single * character (not to be confused with the wildcard entry above) and will match all clients.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>options<\/strong>&nbsp;are comma separated list of options. Some of the options that can be used include:<ul><li><strong>root_squash<\/strong>: Prevents root users connected remotely from having root privileges and assigns them the user ID for the user <strong><code>nfsnobody<\/code><\/strong> thus &#8220;squashing&#8221; the power of the remote root user to the lowest local user, preventing unauthorized alteration of files on the remote server.<\/li><li><strong><code>no_root_squash<\/code><\/strong>: Turn off root squashing. Remote root users are able to change any file on the shared file system. This option is mainly useful for diskless clients. <strong>DO NOT USE THE NO_ROOT_SQUASH OPTION<\/strong>.<\/li><li><strong><code>all_squash<\/code><\/strong>: Map all uids and gids to the anonymous user. Useful for NFS-exported public FTP directories, news spool directories, etc. The opposite option is <strong>no_all_squash<\/strong>, which is the default setting.<\/li><li><strong>anonuid=UID<\/strong> and <strong>anongid=GUID<\/strong>: These options explicitly set the uid and gid of the anonymous account. It is primarily useful for PC\/NFS clients, where you might want all requests appear to be from one user.<\/li><li><strong>secure<\/strong>: This option requires that requests not using gss originate on an Internet port less than IPPORT_RESERVED (1024). This option is on by <strong>default<\/strong>. To turn it off, specify <strong>insecure<\/strong>.<\/li><\/ul><ul><li><strong>rw<\/strong>: Allow both read and write requests on this NFS volume.<\/li><li><strong>ro<\/strong>: Mounts the exported file system in read-only mode. Remote hosts are not able to make changes to the data shared on the file system. This is on by <strong>default<\/strong>.<\/li><li><strong>async<\/strong>: allows the NFS server to violate the NFS protocol and reply to requests before any changes made by that request have been committed to stable storage. It improves performance, but at the cost that an unclean server restart (i.e. a crash) can cause data to be lost or corrupted.<\/li><\/ul>\n<ul class=\"wp-block-list\">\n<li><strong>sync<\/strong>: Reply to requests only after the changes have been committed to stable storage. This is on by <strong>default<\/strong>.<\/li>\n\n\n\n<li><strong>wdelay<\/strong>: Causes the NFS server to delay writing to the disk if it suspects another write request is imminent. This option is on by default.<\/li>\n\n\n\n<li><strong>no_wdelay<\/strong>: Turns off the above feature. This option has no effect if async is also set.<\/li>\n\n\n\n<li><strong>subtree_check<\/strong>: Enables subtree checking. On by <strong>default<\/strong>.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p>Read more on <strong><code>man exports<\/code><\/strong>.<\/p>\n\n\n\n<p>In my setup, below is our NFS share to be shared with the specific host, 192.168.60.18.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/exports<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>\/home 192.168.60.18(rw)<\/code><\/pre>\n\n\n\n<p>This will allow users on the remote host, 192.168.60.18, to access the shared directory \/home on the NFS server, with the ability to make changes (rw). Other options that are on by default include <strong>wdelay<\/strong>, <strong>sync<\/strong>, <strong>secure<\/strong>, <strong>root_squash<\/strong>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"allow-nfs-service-on-firewalld\">Allow NFS Service on Firewalld<\/h4>\n\n\n\n<p>To allow remote hosts to access the NFS shares, you need to allow NFS service through the firewall if firewalld is running:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>firewall-cmd --add-service={nfs,nfs3,mountd,rpc-bind} --permanent\nfirewall-cmd --reload<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"running-nfs-service\">Running NFS Service<\/h4>\n\n\n\n<p>Start and enable both rpcbind and nfs-server<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl enable --now nfs-server rpcbind<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"configure-nfs-client\">Configure NFS client<\/h3>\n\n\n\n<p>After configuring the NFS server, the shared directory or file system has to be mounted on the client so it can be accessed.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"install-nfs-packages-1\">Install NFS Packages<\/h4>\n\n\n\n<p>But before that, ensure that you install NFS packages.<\/p>\n\n\n\n<p>On Ubuntu\/Debian systems;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt install nfs-common<\/code><\/pre>\n\n\n\n<p>On CentOS\/RHEL\/Rocky Linux and similar distros;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>dnf install nfs-utils -y<\/code><\/pre>\n\n\n\n<p>Next, edit the&nbsp;<strong>\/etc\/idmap.conf<\/strong>&nbsp;file and add a domain name with your appropriate domain name as we did for the NFS server above.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sed -i '\/^#Domain\/s\/^#\/\/;\/Domain = \/s\/=.*\/= kifarunix-demo.com\/' \/etc\/idmapd.conf<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"discover-nfs-server-shares\">Discover NFS Server Shares<\/h4>\n\n\n\n<p>Before mounting, you can try to&nbsp;<strong>discover<\/strong>&nbsp;NFS exports, that is, the shares available on the NFS server as shown below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>showmount -e nfs.kifarunix-demo.com<\/code><\/pre>\n\n\n\n<p>Ensure the hostname of the NFS server is resolvable. You can also use the IP address instead of the hostname;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Export list for nfs.kifarunix-demo.com:\n\/home 192.168.60.18<\/code><\/pre>\n\n\n\n<p>Then mount the shared directory<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>mount -t nfs nfs.kifarunix-demo.com:\/home \/mnt<\/code><\/pre>\n\n\n\n<p>Confirm that the shared directory is mounted by using df -hT.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>df -hT -P \/mnt\/<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Filesystem                   Type  Size  Used Avail Use% Mounted on\nnfs.kifarunix-demo.com:\/home nfs4   14G  2.6G   11G  19% \/mnt<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"configuring-automounting\">Configuring Automounting<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"automounting-with-fstab\">Automounting with FSTAB<\/h3>\n\n\n\n<p>NFS share can also be added to&nbsp;<strong>fstab for automounting<\/strong>&nbsp;when the system boots. <strong><code>fstab<\/code><\/strong> is a system configuration file that specifies how the Linux kernel should mount filesystems at boot time. To mount an NFS filesystem using fstab, you need to add a line to the fstab file that specifies the NFS server, the NFS share, and the mount point.<\/p>\n\n\n\n<p>Below is an example of an NFS share mount entry.<\/p>\n\n\n\n<p>Replace the hostname and share name accordingly.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>echo 'nfs.kifarunix-demo.com:\/home \/mnt nfs defaults 0 0' &gt;&gt; \/etc\/fstab<\/code><\/pre>\n\n\n\n<p>The&nbsp;<strong>_netdev<\/strong>&nbsp;mount option can also be used to tell the mount command to mount the file systems only when the network is activated. This option has been replaced by&nbsp;<strong>remote-fs.target<\/strong>&nbsp;systemd unit. To ensure that file systems are mounted once the network is up, the remote-fs.target must be enabled.<\/p>\n\n\n\n<p>To test the usability of the NFS shares, navigate to&nbsp;<em>\/home<\/em>&nbsp;directory on the NFS server and create a <strong>testfile.txt<\/strong>. Check its availability on the mount point on the NFS client. If the file exist the configuration is okay.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"automounting-with-autofs\">Automounting with Autofs<\/h3>\n\n\n\n<p>FSTAB cannot be used to manage several mount points at a time. To manage multiple mount points for the same NFS share, you can use the kernel-based automount utility, the autofs daemon. <strong>autofs<\/strong> is a daemon that automatically mounts filesystems on demand. When a user tries to access a directory that is mounted using autofs, the autofs daemon will automatically mount the filesystem. Once the user has finished accessing the directory, the autofs daemon will unmount the filesystem.<\/p>\n\n\n\n<p>To proceed with the automounting configuration, install&nbsp;<strong>autofs<\/strong>. If you are using other Linux distros, consult their documentation on which package manager to use for installation.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dnf -y install autofs<\/pre>\n\n\n\n<p>Default configuration file for autofs is&nbsp;<strong>\/etc\/auto.master<\/strong>. The master map lists autofs controlled mount points on the system and their corresponding configuration files or network sources called&nbsp;<strong>automount maps<\/strong>.<\/p>\n\n\n\n<p>Edit the&nbsp;<em>\/etc\/auto.master<\/em>&nbsp;file<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/auto.master <\/code><\/pre>\n\n\n\n<p>Add a direct mount point at the end of the file. Direct mounts always have \/- as the starting point in the master map file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/- \/etc\/auto.mount<\/code><\/pre>\n\n\n\n<p>Save and exit the \/etc\/auto.master file.<\/p>\n\n\n\n<p>Edit the mount point (<strong><code>\/etc\/auto.mount<\/code><\/strong>) and create a new map in the form:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>mount-point options<\/strong>&nbsp;<em>location<\/em><\/code><\/pre>\n\n\n\n<p>For example;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>echo '\/mnt -fstype=nfs,rw nfs.kifarunix-demo.com:\/home' &gt;&gt; \/etc\/auto.mount<\/code><\/pre>\n\n\n\n<p>Make sure the mount point&nbsp;directory already exists.<\/p>\n\n\n\n<p>Start and enable autofs:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl enable --now autofs<\/code><\/pre>\n\n\n\n<p>You can reboot your system to verify if the share is auto-mounted!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"other-tutorials\">Other Tutorials<\/h3>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-and-configure-backuppc-on-rocky-linux-8\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install and Configure BackupPC on Rocky Linux 8<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/create-raid-level-10-raid-10-on-ubuntu-20-04\/\" target=\"_blank\" rel=\"noreferrer noopener\">Create RAID Level 10 (RAID 1+0) on Ubuntu 20.04<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we will learn how to Install and Configure NFS server on Rocky Linux 8. Network File system (NFS)&nbsp;is a commonly used file-based<\/p>\n","protected":false},"author":3,"featured_media":9951,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[39,121],"tags":[3923,3927,3924,3587,3925,3926],"class_list":["post-9938","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-storage","category-howtos","tag-install-nfs-rocky-linux-8","tag-nfs-server","tag-nfs-utils-rocky-linux-8","tag-rocky-linux-8","tag-rpcinfo","tag-showmount-nfs","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/9938"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=9938"}],"version-history":[{"count":12,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/9938\/revisions"}],"predecessor-version":[{"id":21703,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/9938\/revisions\/21703"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/9951"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=9938"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=9938"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=9938"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}