{"id":195,"date":"2020-09-26T13:20:38","date_gmt":"2020-09-26T13:20:38","guid":{"rendered":"https:\/\/dft.wiki\/?p=195"},"modified":"2026-06-09T14:57:33","modified_gmt":"2026-06-09T18:57:33","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 choice between NFS and Samba depends on who you are sharing with. Linux supports both NFS and Samba, but Windows only supports 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; 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 the line to match 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 find your network address, run:<\/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 any IP starting with &#8216;<strong>127<\/strong>&#8216;. Use the first three octets of your IP 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>Once the service is running, apply any changes made to <strong>\/etc\/exports<\/strong> with:<\/p>\n<pre>sudo exportfs -ra<\/pre>\n<p>To check the shares on an 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 mount a remote share to a local directory:<\/p>\n<pre>sudo mount 192.168.2.40:\/home\/ubuntu \/tmp\/file-server<\/pre>\n<p>Customize the command to match 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> on the server.<\/td>\n<\/tr>\n<tr>\n<td>\/tmp\/file-server<\/td>\n<td>Local <strong>mount point<\/strong>.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<p>The directory &#8216;<strong>\/tmp\/file-server<\/strong>&#8216; must exist on the local file system. If it does not, run:<\/p>\n<pre>sudo mkdir \/tmp\/file-server\r\nsudo chmos 755 \/tmp\/file-server<\/pre>\n<p>To unmount the share from the local computer:<\/p>\n<pre>sudo umount \/tmp\/file-server<\/pre>\n<p>To <strong>automatically mount on 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 the line to match 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> on the server.<\/td>\n<\/tr>\n<tr>\n<td>\/tmp\/file-server<\/td>\n<td>Local <strong>mount 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> and verify that the share was automatically mounted.<\/p>\n<hr \/>\n<p><strong>BONUS<\/strong><\/p>\n<p>For mobile systems such as laptops, traditional NFS mounts block I\/O when the server becomes unreachable (e.g., when you leave home), which can cause the system to hang. <strong>AutoFS<\/strong> is a more robust solution 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 mounted automatically whenever you access that path.<\/p>\n<pre>ls \/mnt\/sharemount<\/pre>\n<p>Or<\/p>\n<pre>cd \/mnt\/sharemount<\/pre>\n<p>Then verify.<\/p>\n<pre>df -h | grep \/mnt\/sharemount<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The choice between NFS and Samba depends on who you are sharing with. Linux supports [&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":18,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/195\/revisions"}],"predecessor-version":[{"id":5847,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/195\/revisions\/5847"}],"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}]}}