{"id":314,"date":"2018-08-12T09:17:01","date_gmt":"2018-08-12T06:17:01","guid":{"rendered":"http:\/\/kifarunix.com\/?p=314"},"modified":"2024-03-11T08:20:09","modified_gmt":"2024-03-11T05:20:09","slug":"install-and-configure-nfs-server-on-rhel-centos","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-and-configure-nfs-server-on-rhel-centos\/","title":{"rendered":"Install and Configure NFS Server on RHEL\/CentOS"},"content":{"rendered":"\n<p>In this tutorial, we will learn how to install and configure NFS Server on RHEL\/CentOS. Network File system (NFS) <span class=\"st\">is a commonly used file-based storage system that <\/span>allows remote systems <span class=\"st\">to access files over a computer network <\/span>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-rhel-cent-os\">Installing NFS Server on RHEL\/CentOS<\/a><ul><li><a href=\"#simple-setup-architecture\">Simple Setup Architecture<\/a><\/li><li><a href=\"#install-nfs-packages-on-rhel-cent-os\">Install NFS Packages on RHEL\/CentOS<\/a><\/li><li><a href=\"#configure-nfs-server-on-rhel-cent-os\">Configure NFS Server on RHEL\/CentOS<\/a><ul><li><a href=\"#define-id-mapping-domain\">Define ID Mapping Domain<\/a><\/li><li><a href=\"#create-nfs-share-directory\">Create NFS Share Directory<\/a><\/li><li><a href=\"#configure-nfs-exports\">Configure NFS exports<\/a><\/li><li><a href=\"#start-and-enable-nfs-server\">Start and Enable NFS server<\/a><\/li><li><a href=\"#open-firewall-ports-for-nfs\">Open Firewall ports for NFS<\/a><\/li><\/ul><\/li><li><a href=\"#configure-nfs-client-on-rhel-cent-os\">Configure NFS Client on RHEL\/CentOS<\/a><ul><li><a href=\"#define-id-mapping-domain-1\">Define ID Mapping Domain<\/a><\/li><li><a href=\"#mount-the-nfs-share-on-the-client\">Mount the NFS share on the client<\/a><\/li><\/ul><\/li><li><a href=\"#configuring-nfs-share-automounting-on-system-boot\">Configuring NFS Share Automounting on System Boot<\/a><ul><li><a href=\"#automount-using-fstab\">Automount using FSTAB<\/a><\/li><li><a href=\"#automount-using-auto-fs\">Automount using AutoFS<\/a><\/li><\/ul><\/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-rhel-cent-os\">Installing NFS Server on RHEL\/CentOS<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"simple-setup-architecture\">Simple Setup Architecture<\/h3>\n\n\n\n<p>To configure NFS server, we will be using two CentOS 8 and Rocky Linux servers acting as the NFS Server while the other acting as the NFS Client respectively.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>Hostname<\/td><td>IP Address<\/td><td>Role<\/td><td>OS<\/td><\/tr><tr><td><em>fileserver.kifarunix-demo.com<\/em><\/td><td>192.168.56.165<\/td><td>NFS Server<\/td><td>CentOS 9 stream<\/td><\/tr><tr><td><em>client.kifarunix-demo.com<\/em><\/td><td>192.168.56.144<\/td><td>NFS Client<\/td><td>Rocky Linux 9<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-nfs-packages-on-rhel-cent-os\">Install NFS Packages on RHEL\/CentOS<\/h3>\n\n\n\n<p>To <strong>install NFS packages<\/strong> on both the Server and the Client, execute the command below;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>yum <span class=\"hljs-keyword\">install<\/span> nfs-utils -y<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"configure-nfs-server-on-rhel-cent-os\">Configure NFS Server on RHEL\/CentOS<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"define-id-mapping-domain\">Define ID Mapping Domain<\/h4>\n\n\n\n<p>ID mapping is the process of mapping user and group IDs between different systems to ensure that file access permissions are correctly applied.<\/p>\n\n\n\n<p>Thus, once the packages are installed, edit the <strong>\/etc\/idmapd.conf<\/strong> file as follows on NFS server;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim \/etc\/idmapd.conf<\/code><\/pre>\n\n\n\n<p>Uncomment the line below by removing #;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#Domain = local.domain.edu<\/code><\/pre>\n\n\n\n<p> Then replace the domain with your appropriate NFS server domain name.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>Domain = kifarunix-demo.com<\/code><\/pre>\n\n\n\n<p>The domain usually defaults to the host&#8217;s DNS domain name.<\/p>\n\n\n\n<p>Save and exit the file;<\/p>\n\n\n\n<p>Restart the <code>rpcidmapd<\/code> service to apply the changes:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl restart rpcbind<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"create-nfs-share-directory\">Create NFS Share Directory<\/h4>\n\n\n\n<p>Create a directory that you want to share over the network via NFS server. For example, create a directory named &#8220;Shared&#8221; in the &#8220;\/home&#8221; directory.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir \/home\/share<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"configure-nfs-exports\">Configure NFS exports<\/h4>\n\n\n\n<p>An <strong><code>export<\/code><\/strong> is a directory or file system that is made available to remote clients for sharing. When you set up an NFS server, you can specify which directories or file systems on the server should be available for clients to access. This is done by configuring NFS exports. Once an export is configured, clients can access it by mounting it as a local file system.<\/p>\n\n\n\n<p>Thus, edit the file <strong>\/etc\/exports<\/strong>;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim \/etc\/exports<\/code><\/pre>\n\n\n\n<p>Add <em>file system<\/em> or <em>directory<\/em> to be exported to client and specify the options to apply as in the screenshot below:<\/p>\n\n\n\n<p>Each entry for an exported file system has the following structure:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>export host(<span class=\"hljs-keyword\">options<\/span>)<\/code><\/pre>\n\n\n\n<p>where:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>export<\/strong> is the file system or directory to be mounted on remote host<\/li>\n\n\n\n<li><strong>host<\/strong> is the remote host (Network, host, or every system,*,)<\/li>\n\n\n\n<li><strong>options<\/strong> are comma separated list of options<\/li>\n<\/ul>\n\n\n\n<p>For our case:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>\/home\/share 192.168.56.0\/24(rw,sync,no_root_squash)<\/code><\/pre>\n\n\n\n<p>Options used as in the above are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>rw<\/strong> allows the client server both read and write access within the shared directory.<\/li>\n\n\n\n<li><strong>sync<\/strong> ensures that changes made are synchronized immediately.<\/li>\n\n\n\n<li><strong>no_root_squash<\/strong> allows root user to write files to the NFS share.<\/li>\n<\/ul>\n\n\n\n<p>Save and exit the file.<\/p>\n\n\n\n<p>For more options, check <a href=\"https:\/\/linux.die.net\/man\/5\/nfs\" target=\"_blank\" rel=\"noreferrer noopener\">nfs man pages<\/a>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"start-and-enable-nfs-server\">Start and Enable NFS server<\/h4>\n\n\n\n<p>Start the NFS server and enable it to start at boot time using the following commands:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl enable --now nfs-server<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"open-firewall-ports-for-nfs\">Open Firewall ports for NFS<\/h4>\n\n\n\n<p>There are several ports that need to be open in the firewall on both the server and client machines. Here are the ports that should be open:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Port 111: This is the portmapper daemon, which maps RPC services to port numbers. Both TCP and UDP need to be open.<\/li>\n\n\n\n<li>Port 2049: This is the NFS daemon, which handles all NFS requests. Both TCP and UDP need to be open.<\/li>\n\n\n\n<li>Port 20048: This is the NFSv4 protocol. Both TCP and UDP need to be open.<\/li>\n\n\n\n<li>Port 875: This is the mountd daemon, which handles mount requests. Both TCP and UDP need to be open.<\/li>\n\n\n\n<li>Port 892: This is the rpcbind daemon, which is used to manage RPC services. Both TCP and UDP need to be open.<\/li>\n<\/ol>\n\n\n\n<p>Allow these ports using the commands below;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo firewall-cmd --permanent --add-service=nfs\nsudo firewall-cmd --permanent --add-service=rpc-bind\nsudo firewall-cmd --permanent --add-service=mountd\nsudo firewall-cmd --reload<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"configure-nfs-client-on-rhel-cent-os\">Configure NFS Client on RHEL\/CentOS<\/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=\"define-id-mapping-domain-1\">Define ID Mapping Domain<\/h4>\n\n\n\n<p>Just like it was done on the NFS server, edit the <strong>\/etc\/idmap.conf<\/strong> file and add a domain name like before.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim \/etc\/idmap.conf<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;General]\n...\n<strong>Domain = kifarunix-demo.com<\/strong><\/code><\/pre>\n\n\n\n<p>Save and exit the file.<\/p>\n\n\n\n<p>Enable and start rpcbind service<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl restart rpcbind<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"mount-the-nfs-share-on-the-client\">Mount the NFS share on the client<\/h4>\n\n\n\n<p>Mount the shared directory on NFS client using the mount command.<\/p>\n\n\n\n<p>Before mounting, you need to <code>discover<\/code> (<em>finds and accesses NFS exports on an NFS server<\/em>) NFS exports, that is, the shares available on the NFS server as shown below.<\/p>\n\n\n\n<p>There are two ways to discover which file systems an NFS server exports;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Using showmount<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>showmount -e NFS-Server-Address<\/code><\/pre>\n\n\n\n<p>e.g;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>showmount -e fileserver<\/code><\/pre>\n\n\n\n<p>Sample output;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Export list for fileserver:\n\/home\/share 192.168.56.0\/24<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Using mount command<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>mount NFS-Server:\/ \/mnt\/<\/code><\/pre>\n\n\n\n<p>e.g;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mount -t nfs fileserver:\/ \/mnt<\/code><\/pre>\n\n\n\n<p>Confirm that the shared directory is mounted by using df -hT. See the last line in the screenshot below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>df -hT<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>...\nfileserver:\/           nfs4      7.8G  1.2G  6.6G  15% \/mnt\nfileserver:\/home       nfs4      7.8G  1.2G  6.6G  15% \/mnt\/home\nfileserver:\/home\/share nfs4      7.8G  1.2G  6.6G  15% \/mnt\/home\/share<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"configuring-nfs-share-automounting-on-system-boot\">Configuring NFS Share Automounting on System Boot<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Automount using FSTAB<\/li>\n\n\n\n<li>Automount using AutoFS<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"automount-using-fstab\">Automount using FSTAB<\/h4>\n\n\n\n<p>Edit the <code>\/etc\/fstab<\/code> file and add an entry for the NFS share. The entry should include the IP address of the NFS server, the path to the NFS share, the mount point directory, and the mount options. For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim \/etc\/fstab<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>fileserver.kifarunix-demo.com:\/home\/ \/mnt               nfs     defaults        0 0<\/code><\/pre>\n\n\n\n<p>Save the <code>\/etc\/fstab<\/code> file and exit the editor.<\/p>\n\n\n\n<p>You can test the mount by running the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code><code>sudo mount -a<\/code><\/pre>\n\n\n\n<p>When system boots, the share should also automount.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"automount-using-auto-fs\">Automount using AutoFS<\/h4>\n\n\n\n<p>To enable auto-mounting via AutoFS, first install autofs package on the client;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>yum -y <span class=\"hljs-keyword\">install<\/span> autofs<\/code><\/pre>\n\n\n\n<p>Default configuration file for autofs is <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 <strong>automount maps<\/strong>.<\/p>\n\n\n\n<p>Edit the <em>\/etc\/auto.master<\/em> file<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span class=\"hljs-keyword\">vim<\/span> \/etc\/auto.master<\/code><\/pre>\n\n\n\n<p>Add a direct mount point at the <strong>end of the file<\/strong>. Direct mounts always have \/- as the starting point in the master map file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/- <span class=\"hljs-regexp\">\/etc\/<\/span>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> <em>location<\/em><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>vim <span class=\"hljs-regexp\">\/etc\/<\/span>auto.mount<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>\/mnt -fstype=nfs,rw fileserver.kifarunix-demo.com:\/home<\/code><\/pre>\n\n\n\n<p>Make sure the <strong>\/mnt<\/strong> directory exists.<\/p>\n\n\n\n<p>Start and enable autofs:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span class=\"hljs-attribute\">systemctl<\/span> enable --now autofs<\/code><\/pre>\n\n\n\n<p>Navigate into the <strong>\/mnt<\/strong> directory and run <strong>ll<\/strong> command and you should be able to see the shared files.<\/p>\n\n\n\n<p>or simply check mounting;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>df -hT -P \/mnt<\/code><\/pre>\n\n\n\n<p>To that end, you have learnt;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>how to install and configure both the NFS server and NFS client,<\/li>\n\n\n\n<li>NFS mounting on fstab and auto-mounting using autofs<\/li>\n<\/ul>\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-nfs-server-on-rocky-linux-8\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install and Configure NFS Server on Rocky Linux 8<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/easy-way-to-setup-nfs-server-on-ubuntu-20-04\/\" target=\"_blank\" rel=\"noreferrer noopener\">Easy way to Setup NFS Server 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 RHEL\/CentOS. Network File system (NFS) is a commonly used file-based storage<\/p>\n","protected":false},"author":1,"featured_media":16519,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[39,48],"tags":[6642,6640,6639,6643,6638],"class_list":["post-314","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-storage","category-nfs","tag-automount-nfs-share-on-boot","tag-centos-autofs","tag-centos-nfs-server","tag-how-to-install-nfs-on-centos","tag-install-and-configure-nfs-server-on-rhel-centos","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\/314"}],"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\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=314"}],"version-history":[{"count":10,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/314\/revisions"}],"predecessor-version":[{"id":20967,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/314\/revisions\/20967"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/16519"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=314"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=314"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=314"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}