kifarunix-demo.com<\/code><\/em>, with your server’s domain name.<\/strong><\/p>\n\n\n\nsed -i '\/^#Domain\/s\/^#\/\/;\/Domain = \/s\/=.*\/= kifarunix-demo.com\/' \/etc\/idmapd.conf<\/pre>\n\n\n\nidmapd <\/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\nDefine NFS Server Shares<\/h4>\n\n\n\n
The file \/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\nYou need to edit this file and add file system<\/em> or directory<\/em> to be exported to client and specify the options to apply to those shares.<\/p>\n\n\n\nNB: Each entry for an exported file system has the following structure:<\/p>\n\n\n\n
export host(options)<\/code><\/pre>\n\n\n\nwhere:<\/p>\n\n\n\n
\n- export<\/strong> is the file system or directory to be mounted on remote host<\/li>\n\n\n\n
- host<\/strong> is the remote host\/client to be allowed to access a shared folder. The host can be defined as:\n
\n- 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
- IP networks<\/strong>: You can define hosts by specifying an IP address and netmask pair as address\/netmask.<\/li>\n\n\n\n
- 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
- 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
- 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
\n- options<\/strong> are comma separated list of options. Some of the options that can be used include:
- root_squash<\/strong>: Prevents root users connected remotely from having root privileges and assigns them the user ID for the user
nfsnobody<\/code><\/strong> thus “squashing” the power of the remote root user to the lowest local user, preventing unauthorized alteration of files on the remote server.<\/li>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. DO NOT USE THE NO_ROOT_SQUASH OPTION<\/strong>.<\/li>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 no_all_squash<\/strong>, which is the default setting.<\/li>- anonuid=UID<\/strong> and 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>
- 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 default<\/strong>. To turn it off, specify insecure<\/strong>.<\/li><\/ul>
- rw<\/strong>: Allow both read and write requests on this NFS volume.<\/li>
- 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 default<\/strong>.<\/li>
- 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
\n- sync<\/strong>: Reply to requests only after the changes have been committed to stable storage. This is on by default<\/strong>.<\/li>\n\n\n\n
- 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
- no_wdelay<\/strong>: Turns off the above feature. This option has no effect if async is also set.<\/li>\n\n\n\n
- subtree_check<\/strong>: Enables subtree checking. On by default<\/strong>.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n
Read more on man exports<\/code><\/strong>.<\/p>\n\n\n\nIn my setup, below is our NFS share to be shared with the specific host, 192.168.60.18.<\/p>\n\n\n\n
vim \/etc\/exports<\/code><\/pre>\n\n\n\n\/home 192.168.60.18(rw)<\/code><\/pre>\n\n\n\nThis 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 wdelay<\/strong>, sync<\/strong>, secure<\/strong>, root_squash<\/strong>.<\/p>\n\n\n\nAllow NFS Service on Firewalld<\/h4>\n\n\n\n
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
firewall-cmd --add-service={nfs,nfs3,mountd,rpc-bind} --permanent\nfirewall-cmd --reload<\/code><\/pre>\n\n\n\nRunning NFS Service<\/h4>\n\n\n\n
Start and enable both rpcbind and nfs-server<\/p>\n\n\n\n
systemctl enable --now nfs-server rpcbind<\/code><\/pre>\n\n\n\nAfter 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
Install NFS Packages<\/h4>\n\n\n\n
But before that, ensure that you install NFS packages.<\/p>\n\n\n\n
On Ubuntu\/Debian systems;<\/p>\n\n\n\n
apt install nfs-common<\/code><\/pre>\n\n\n\nOn CentOS\/RHEL\/Rocky Linux and similar distros;<\/p>\n\n\n\n
dnf install nfs-utils -y<\/code><\/pre>\n\n\n\nNext, edit the \/etc\/idmap.conf<\/strong> file and add a domain name with your appropriate domain name as we did for the NFS server above.<\/p>\n\n\n\nsed -i '\/^#Domain\/s\/^#\/\/;\/Domain = \/s\/=.*\/= kifarunix-demo.com\/' \/etc\/idmapd.conf<\/code><\/pre>\n\n\n\nDiscover NFS Server Shares<\/h4>\n\n\n\n
Before mounting, you can try to discover<\/strong> NFS exports, that is, the shares available on the NFS server as shown below.<\/p>\n\n\n\nshowmount -e nfs.kifarunix-demo.com<\/code><\/pre>\n\n\n\nEnsure the hostname of the NFS server is resolvable. You can also use the IP address instead of the hostname;<\/p>\n\n\n\n
Export list for nfs.kifarunix-demo.com:\n\/home 192.168.60.18<\/code><\/pre>\n\n\n\nThen mount the shared directory<\/p>\n\n\n\n
mount -t nfs nfs.kifarunix-demo.com:\/home \/mnt<\/code><\/pre>\n\n\n\nConfirm that the shared directory is mounted by using df -hT.<\/p>\n\n\n\n
df -hT -P \/mnt\/<\/code><\/pre>\n\n\n\nFilesystem Type Size Used Avail Use% Mounted on\nnfs.kifarunix-demo.com:\/home nfs4 14G 2.6G 11G 19% \/mnt<\/code><\/pre>\n\n\n\nConfiguring Automounting<\/h2>\n\n\n\nAutomounting with FSTAB<\/h3>\n\n\n\n
NFS share can also be added to fstab for automounting<\/strong> when the system boots. 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\nBelow is an example of an NFS share mount entry.<\/p>\n\n\n\n
Replace the hostname and share name accordingly.<\/p>\n\n\n\n
echo 'nfs.kifarunix-demo.com:\/home \/mnt nfs defaults 0 0' >> \/etc\/fstab<\/code><\/pre>\n\n\n\nThe _netdev<\/strong> 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 remote-fs.target<\/strong> 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\nTo test the usability of the NFS shares, navigate to \/home<\/em> directory on the NFS server and create a 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\nAutomounting with Autofs<\/h3>\n\n\n\n
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. 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\nTo proceed with the automounting configuration, install autofs<\/strong>. If you are using other Linux distros, consult their documentation on which package manager to use for installation.<\/p>\n\n\n\ndnf -y install autofs<\/pre>\n\n\n\nDefault configuration file for autofs is \/etc\/auto.master<\/strong>. The master map lists autofs controlled mount points on the system and their corresponding configuration files or network sources called automount maps<\/strong>.<\/p>\n\n\n\nEdit the \/etc\/auto.master<\/em> file<\/p>\n\n\n\nvim \/etc\/auto.master <\/code><\/pre>\n\n\n\nAdd 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
\/- \/etc\/auto.mount<\/code><\/pre>\n\n\n\nSave and exit the \/etc\/auto.master file.<\/p>\n\n\n\n
Edit the mount point (\/etc\/auto.mount<\/code><\/strong>) and create a new map in the form:<\/p>\n\n\n\nmount-point options<\/strong> location<\/em><\/code><\/pre>\n\n\n\nFor example;<\/p>\n\n\n\n
echo '\/mnt -fstype=nfs,rw nfs.kifarunix-demo.com:\/home' >> \/etc\/auto.mount<\/code><\/pre>\n\n\n\nMake sure the mount point directory already exists.<\/p>\n\n\n\n
Start and enable autofs:<\/p>\n\n\n\n
systemctl enable --now autofs<\/code><\/pre>\n\n\n\nYou can reboot your system to verify if the share is auto-mounted!<\/p>\n\n\n\n
Other Tutorials<\/h3>\n\n\n\n
Install and Configure BackupPC on Rocky Linux 8<\/a><\/p>\n\n\n\nCreate RAID Level 10 (RAID 1+0) on Ubuntu 20.04<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"In this tutorial, we will learn how to Install and Configure NFS server on Rocky Linux 8. Network File system (NFS) 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}]}}