{"id":195,"date":"2020-09-26T13:20:38","date_gmt":"2020-09-26T13:20:38","guid":{"rendered":"https:\/\/dft.wiki\/?p=195"},"modified":"2025-12-28T13:52:46","modified_gmt":"2025-12-28T18:52:46","slug":"nfs-and-samba-simplified","status":"publish","type":"post","link":"https:\/\/dft.wiki\/?p=195","title":{"rendered":"NFS Server and Client on Ubuntu"},"content":{"rendered":"<p>The decision of using NFS or Samba only depends on who you are sharing with. Linux can communicate with NFS and SAMBA, but Windows can communicate only with SAMBA.<\/p>\n<p>To learn about SAMBA file-sharing read the following post: <strong>SAMBA Server and Client on Ubuntu (18.04~24.04 LTS)<\/strong> [<a href=\"https:\/\/dft.wiki\/?p=1888\">Link<\/a>].<\/p>\n<hr \/>\n<p><strong>SERVER &#8211; <\/strong><strong>NFS CONFIG<\/strong><\/p>\n<pre>sudo apt update\r\nsudo apt install nfs-kernel-server rpcbind -y\r\nsudo ufw allow nfs\r\nsudo nano \/etc\/exports<\/pre>\n<p>Add this line at the end of the file:<\/p>\n<pre>\/home\/ubuntu 192.168.2.0\/24(rw,sync,no_subtree_check)<\/pre>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" class=\"wp-image-328\" src=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2020\/09\/image-22.png\" alt=\"\" \/><\/figure>\n<p>Customize this command to meet your network:<\/p>\n<figure class=\"wp-block-table is-style-stripes\">\n<table>\n<tbody>\n<tr>\n<td>\/home\/ubuntu<\/td>\n<td>The<strong> directory being shared<\/strong>.<\/td>\n<\/tr>\n<tr>\n<td>192.168.2.0\/24<\/td>\n<td>Your <strong>network ID<\/strong> (check your network).<\/td>\n<\/tr>\n<tr>\n<td>rw<\/td>\n<td><strong>Read and Write<\/strong> (<em>ro would be Read Only<\/em>).<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<p>To know your network address issue:<\/p>\n<pre>hostname -I<\/pre>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" class=\"wp-image-344\" src=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2020\/09\/image-27.png\" alt=\"\" \/><\/figure>\n<p>Ignore the IPs starting with &#8216;<strong>127<\/strong>&#8216;, and use the first three blocks of the IP according to your network to replace &#8216;<strong>192.168.2<\/strong>&#8216;.<\/p>\n<pre>sudo systemctl restart nfs-kernel-server\r\nsudo systemctl status nfs-kernel-server<\/pre>\n<p>OR<\/p>\n<pre>sudo service nfs-kernel-server restart\r\nsudo service nfs-kernel-server status<\/pre>\n<p>When the service is running use the following command to apply changes on <strong>\/etc\/exports<\/strong>:<\/p>\n<pre>sudo exportfs -ra<\/pre>\n<p>To check the shares on a NFS server locally:<\/p>\n<pre>showmount -e<\/pre>\n<hr \/>\n<p><strong>CLIENT &#8211; NFS MOUNT<\/strong><\/p>\n<pre>sudo apt update\r\nsudo apt install nfs-common -y<\/pre>\n<p>Check connectivity:<\/p>\n<pre>showmount -e 192.168.2.40<\/pre>\n<p>To eventually mount one remote share in a local file system issue:<\/p>\n<pre>sudo mount 192.168.2.40:\/home\/ubuntu \/tmp\/file-server<\/pre>\n<p>Customize this command to meet your network:<\/p>\n<figure class=\"wp-block-table is-style-stripes\">\n<table>\n<tbody>\n<tr>\n<td>192.168.2.40<\/td>\n<td>IP <strong>address of the server<\/strong>.<\/td>\n<\/tr>\n<tr>\n<td>\/home\/ubuntu<\/td>\n<td>The <strong>directory being shared<\/strong> in the server.<\/td>\n<\/tr>\n<tr>\n<td>\/tmp\/file-server<\/td>\n<td>Local <strong>mounting point<\/strong>.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<p>The directory &#8216;<strong>\/tmp\/file-server<\/strong>&#8216; has to exist in the local file system. If it does not exist issue:<\/p>\n<pre>sudo mkdir \/tmp\/file-server\r\nsudo chmos 755 \/tmp\/file-server<\/pre>\n<p>The following command unmounts from the local computer:<\/p>\n<pre>sudo umount \/tmp\/file-server<\/pre>\n<p>To make it <strong>automatically mount on the boot<\/strong>:<\/p>\n<pre>sudo nano \/etc\/fstab<\/pre>\n<p>Add this line at the end of the file:<\/p>\n<pre>192.168.2.40:\/home\/ubuntu \/tmp\/file-server nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0<\/pre>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" class=\"wp-image-327\" src=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2020\/09\/image-21.png\" alt=\"\" \/><\/figure>\n<p>Customize this command to meet your network:<\/p>\n<figure class=\"wp-block-table is-style-stripes\">\n<table>\n<tbody>\n<tr>\n<td>192.168.2.40<\/td>\n<td>IP <strong>address of the server<\/strong>.<\/td>\n<\/tr>\n<tr>\n<td>\/home\/ubuntu<\/td>\n<td>The <strong>directory being shared<\/strong> in the server.<\/td>\n<\/tr>\n<tr>\n<td>\/tmp\/file-server<\/td>\n<td>Local <strong>mounting point<\/strong>.<\/td>\n<\/tr>\n<tr>\n<td>nfs<\/td>\n<td>Specifies the protocol &#8216;<strong>nfs<\/strong>&#8216;.<\/td>\n<\/tr>\n<tr>\n<td>auto,nofail,noatime,nolock,<br \/>\nintr,tcp,actimeo=1800 0 0<\/td>\n<td>Keep these arguments as they are.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<p><strong>Restart the client<\/strong> host and check if the share was automatically mounted.<\/p>\n<hr \/>\n<p><strong>BONUS<\/strong><\/p>\n<p>Portable mounts for mobile systems, such as laptops on wiki networks. The problem is that traditional NFS mounts block I\/O when the server disappears (e.g., when you leave home), which can make your system hang. <strong>AutoFS<\/strong> is the most robust approach for intermittent connectivity [<a href=\"https:\/\/github.com\/distrotech\/autofs\">Link<\/a>].<\/p>\n<pre>sudo apt install autofs -y\r\necho '\/mnt\/ \/etc\/auto.nfs --timeout=120' | sudo tee -a \/etc\/auto.master\r\nsudo nano \/etc\/auto.nfs<\/pre>\n<p>Add entries following the example below.<\/p>\n<pre>sharemount -fstype=nfs4,rw,soft,intr,timeo=5,retrans=2 192.168.1.10:\/export\/share<\/pre>\n<p>Reload the configuration.<\/p>\n<pre>sudo systemctl restart autofs<\/pre>\n<p><strong>Note:<\/strong> a directory called <code>\/mnt\/sharemount<\/code> will be created, and the remote share will be automatically mounted whenever you try to access this path.<\/p>\n<pre>ls \/mnt\/sharemount<\/pre>\n<p>Or<\/p>\n<pre>cd \/mnt\/sharemount<\/pre>\n<p>Then, check.<\/p>\n<pre>df -h | grep \/mnt\/sharemount<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The decision of using NFS or Samba only depends on who you are sharing with. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,6],"tags":[],"class_list":["post-195","post","type-post","status-publish","format-standard","hentry","category-linux","category-raspberry-pi"],"_links":{"self":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/195","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=195"}],"version-history":[{"count":17,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/195\/revisions"}],"predecessor-version":[{"id":5201,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/195\/revisions\/5201"}],"wp:attachment":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}