{"id":343,"date":"2018-08-13T13:34:15","date_gmt":"2018-08-13T10:34:15","guid":{"rendered":"http:\/\/kifarunix.com\/?p=343"},"modified":"2024-03-10T17:52:14","modified_gmt":"2024-03-10T14:52:14","slug":"how-to-configure-nfs-server-on-ubuntu-18-04-server","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/how-to-configure-nfs-server-on-ubuntu-18-04-server\/","title":{"rendered":"How to Configure NFS Server on Ubuntu 18.04"},"content":{"rendered":"\n<p>In this tutorial, we will discuss how to configure NFS server on Ubuntu 18.04 server. 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=\"#configuring-nfs-server-on-ubuntu-18-04-server\">Configuring NFS Server on Ubuntu 18.04 Server<\/a><ul><li><a href=\"#install-nfs-server-packages\">Install NFS Server Packages<\/a><\/li><li><a href=\"#configure-nfs-server-id-mapping-domain\">Configure NFS Server ID Mapping Domain<\/a><\/li><li><a href=\"#configure-the-nfs-exports\">Configure the NFS Exports<\/a><\/li><li><a href=\"#open-nfs-server-ports-on-firewall\">Open NFS Server Ports on Firewall<\/a><\/li><li><a href=\"#restart-nfs-service\">Restart NFS Service<\/a><\/li><\/ul><\/li><li><a href=\"#configure-nfs-client-on-ubuntu\">Configure NFS Client on Ubuntu<\/a><ul><li><a href=\"#install-nfs-client-packages\">Install NFS Client Packages<\/a><\/li><li><a href=\"#configure-nfs-domain-for-id-mapping\">Configure NFS Domain for ID mapping<\/a><\/li><li><a href=\"#create-a-directory-to-mount-the-remote-share\">Create a directory to mount the remote share<\/a><\/li><li><a href=\"#check-nfs-server-export-list\">Check NFS server Export List<\/a><\/li><li><a href=\"#mount-the-nfs-shares-on-nfs-client\">Mount the NFS shares on NFS client<\/a><\/li><\/ul><\/li><li><a href=\"#conclusion\">Conclusion<\/a><\/li><li><a href=\"#other-tutorials\">Other Tutorials<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"configuring-nfs-server-on-ubuntu-18-04-server\">Configuring NFS Server on Ubuntu 18.04 Server<\/h2>\n\n\n\n<p>NFS operates on a server-client architecture and therefore to demonstrate how to configure NFS server to share directories and files over the network and Ubuntu 18.04 desktop as our NFS client, these are the details of our nfs server and client are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>NFS server<\/strong>: nfs01.example.com, 192.168.43.154<\/li>\n\n\n\n<li><strong>NFS client<\/strong>: usera.example.com, 192.168.43.214<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-nfs-server-packages\">Install NFS Server Packages<\/h3>\n\n\n\n<p>Install NFS server packages on the NFS server host<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt install nfs-kernel-server -y<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"configure-nfs-server-id-mapping-domain\">Configure NFS Server ID Mapping Domain<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The &#8220;Domain&#8221; option is used to specify the domain name for id mapping. ID mapping is the process of mapping user and group IDs between different systems to ensure that file access permissions are correctly applied.<\/li>\n\n\n\n<li>When a user accesses a file on an NFS share, the NFS server needs to know which user or group on the client system is requesting the access. The NFS server uses the user and group IDs provided by the client system to verify the user&#8217;s identity and apply the appropriate access permissions. However, the user and group IDs on the client system may be different from the IDs on the NFS server. This can cause a mismatch in the file access permissions and prevent the user from accessing the files.<\/li>\n\n\n\n<li>To address this issue, NFS uses ID mapping to map the user and group IDs between the client and server systems. When a user accesses a file on an NFS share, the NFS client maps the user and group IDs from the client system to new IDs that are recognized by the NFS server. This ensures that the user is correctly identified and the appropriate access permissions are applied.<\/li>\n\n\n\n<li>ID mapping is handled by the <code>rpc.idmapd<\/code> daemon on both the NFS client and server. The ID mapping settings are defined in the <code>\/etc\/idmapd.conf<\/code> file. The file defines how the IDs are mapped between the client and server systems, including the mapping mechanism, domain, and cache size.<\/li>\n<\/ul>\n\n\n\n<p>Thus, edit the <tt><code>\/etc\/idmapd.conf<\/code><\/tt> file and uncomment line 6 and set it to the correct domain name.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/idmapd.conf<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>[General]\n...\nDomain = kifarunix-demo.com\n...<\/code><\/pre>\n\n\n\n<p>Save and exit the file.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"configure-the-nfs-exports\">Configure the NFS Exports<\/h3>\n\n\n\n<p>Exports are <span class=\"st\"> file systems or directories on an NFS server that are shared to or accessible to NFS clients.<\/span><\/p>\n\n\n\n<p>So we are going to create a general directory and a private directory where the files we would like to share publicly or privately respectively over the network will be stored.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>mkdir \/opt\/{general,private}<\/code><\/pre>\n\n\n\n<p>To set up a directory for sharing, specify the directory to be shared, IP addresses\/networks or domain names (if you have DNS server) of the systems to share with along the options associated with shared directory in the format:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nfshare &nbsp; nfsclient_IP or nfsclients_net or_domainname(sharingoptions)<\/code><\/pre>\n\n\n\n<p>Edit the <strong><code>\/etc\/exports<\/code><\/strong> file and set up the above directories for sharing.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/exports<\/code><\/pre>\n\n\n\n<p>In our case, we will share the general directory with anyone and the private directory with specific clients.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>...\n# NFS share directory\n\/opt\/general    *(ro,sync,root_squash,subtree_check)\n\/opt\/private    192.168.43.214(rw,sync,no_root_squash,no_subtree_check)<\/code><\/pre>\n\n\n\n<p>The mount options used above are;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>ro<\/code><\/strong> mounts the directory on the client with read only permissions.<\/li>\n\n\n\n<li><strong><code>rw<\/code><\/strong> mounts the shared directory on the client with read write permissions<\/li>\n\n\n\n<li><strong><code>sync<\/code><\/strong> ensures that any changes made to the shared directory is synchronized between the server and the client.<\/li>\n\n\n\n<li><strong><code>root_squash<\/code><\/strong> maps the remote root user privileges into a non-privileged user on the NFS server<\/li>\n\n\n\n<li><strong><code>no_root_squash<\/code><\/strong> allows remote user to access the share with full privileges of the root user on the NFS server.<\/li>\n\n\n\n<li><strong><code>subtree_check<\/code><\/strong> ensures that in case a directory instead of a block device is exported, the nfs server must check the existence of files in the shared directory for every request made.<\/li>\n\n\n\n<li><strong><code>no_subtree_check<\/code><\/strong> specifies that the nfs server should not verify the availability of the files in the export for every request.<\/li>\n<\/ul>\n\n\n\n<p>For a deeper insight into the export mount options, check <code>man 5 exports<\/code><\/p>\n\n\n\n<p>Once done with editing, save the file.<\/p>\n\n\n\n<p>Next, run the following command to update the exported\/shared directories.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>exportfs -arvf<\/code><\/pre>\n\n\n\n<p>Sample output;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>exporting 192.168.43.214:\/opt\/private\nexporting *:\/opt\/general<\/code><\/pre>\n\n\n\n<p>See the man page for exportfs to more information on options used above<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>man exportfs<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"open-nfs-server-ports-on-firewall\">Open NFS Server Ports on Firewall<\/h3>\n\n\n\n<p>If firewall is running on NFS server, allow access to the nfs share from the client.<\/p>\n\n\n\n<p>We are using UFW in our server, hence;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ufw allow from 192.168.43.214 to any port nfs<\/code><\/pre>\n\n\n\n<p>Similarly, you might need to control which port NFS server will use to handles mount requests from NFS clients. <strong><code>rpc-bind<\/code><\/strong> dynamically assigns ports for RPC services and this can cause issues with access to the shares<\/p>\n\n\n\n<p>To control this and ensure that the ports are static, edit the <code>\/etc\/nfs.conf<\/code> and set the port value to any port of your choice that is currently not used by any service.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim \/etc\/nfs.conf<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;mountd]\n...\n<strong>port=53603<\/strong>\n...<\/code><\/pre>\n\n\n\n<p>Save and exit the file.<\/p>\n\n\n\n<p>Open the RPC mount port on firewall;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ufw allow from 192.168.43.214 to any port 53603\/udp<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>ufw allow from 192.168.43.214 to any port 53603\/tcp<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"restart-nfs-service\">Restart NFS Service<\/h3>\n\n\n\n<p>If all is well, restart NFS service so as to make the share available to NFS clients.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl restart nfs-kernel-server<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"configure-nfs-client-on-ubuntu\">Configure NFS Client on Ubuntu<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-nfs-client-packages\">Install NFS Client Packages<\/h3>\n\n\n\n<p>Install NFS client packages on your NFS client system;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt install nfs-common -y<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"configure-nfs-domain-for-id-mapping\">Configure NFS Domain for ID mapping<\/h3>\n\n\n\n<p>Edit the <tt><code>\/etc\/idmapd.conf<\/code><\/tt> file and un-comment line 6 and set it to the correct domain name.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/idmapd.conf<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>...\nDomain = kifarunix-demo.com\n...<\/code><\/pre>\n\n\n\n<p>Save and exit the file.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"create-a-directory-to-mount-the-remote-share\">Create a directory to mount the remote share<\/h3>\n\n\n\n<p>To access the remote shared directories on the client, we need to mount those directories on the NFS client.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>mkdir -p \/nfs-shares\/{general,private}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"check-nfs-server-export-list\">Check NFS server Export List<\/h3>\n\n\n\n<p>Run the following command to verify the export list on NFS server;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>showmount -e 192.168.43.154<\/code><\/pre>\n\n\n\n<p>Sample output;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>Export list for 192.168.43.154:\n\/opt\/general *\n\/opt\/private 192.168.43.214<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"mount-the-nfs-shares-on-nfs-client\">Mount the NFS shares on NFS client<\/h3>\n\n\n\n<p>Mount the exports on NFS client as shown below<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>mount -t nfs 192.168.43.154:\/opt\/general \/nfs-shares\/general<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>mount -t nfs 192.168.43.154:\/opt\/private \/nfs-shares\/private\/<\/code><\/pre>\n\n\n\n<p>Verify the mounting with the following command;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>df -hT<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\nFilesystem\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Type\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Size\u00a0\u00a0\u00a0 Used Avail Use%\u00a0 Mounted on\nudev\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 devtmpfs\u00a0      697M\u00a0      0\u00a0 697M\u00a0\u00a0 0%\u00a0 \/dev\ntmpfs\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 tmpfs\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0   146M\u00a0   1.6M  144M\u00a0\u00a0 2%\u00a0 \/run\n\/dev\/mapper\/ubuntu--vg-root ext4\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0               8.9G\u00a0\u00a0  4.1G\u00a0 4.3G\u00a0 50%  \/\n[...]\n<strong>192.168.43.154:\/opt\/general     \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 nfs4           8.9G\u00a0\u00a0  1.7G\u00a0 6.7G\u00a0 21%\u00a0 \/nfs-shares\/general<\/strong>\n<strong>192.168.43.154:\/opt\/private\u00a0              nfs4           8.9G\u00a0\u00a0  1.7G\u00a0 6.7G\u00a0 21%\u00a0 \/nfs-shares\/private<\/strong>\n<\/code><\/pre>\n\n\n\n<p>As you can see, both of the shares have been mounted.<\/p>\n\n\n\n<p>To finalize on this, let us create some files on the NFS server and verify that the same becomes available to the client.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>touch \/opt\/general\/public-files.txt \/opt\/private\/private-files.txt<\/code><\/pre>\n\n\n\n<p>On the client:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ls \/nfs-shares\/general\/\npublic-files.txt<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ls \/nfs-shares\/private\/\nprivate-files.txt<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\">Conclusion<\/h2>\n\n\n\n<p>And that is how you can easily setup NFS Server on Ubuntu 18.04. You can now be able to access the exports from Ubuntu 18.04 desktop.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"other-tutorials\">Other Tutorials<\/h2>\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 discuss how to configure NFS server on Ubuntu 18.04 server. Network File system (NFS) is a commonly used file-based storage<\/p>\n","protected":false},"author":1,"featured_media":9050,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[39,48,64],"tags":[6651,6655,69,6652,70,6653,6654,67],"class_list":["post-343","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-storage","category-nfs","category-ubuntu-18-04","tag-install-nfs-server-ubuntu-18-04","tag-mountd","tag-nfs","tag-nfs-client-ubuntu-18-04","tag-nfs-exports","tag-open-nfs-ports-on-firewall","tag-rpc","tag-ubuntu-18-04","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\/343"}],"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=343"}],"version-history":[{"count":17,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/343\/revisions"}],"predecessor-version":[{"id":20956,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/343\/revisions\/20956"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/9050"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=343"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=343"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}