{"id":72,"date":"2023-08-05T07:22:20","date_gmt":"2023-08-05T07:22:20","guid":{"rendered":"http:\/\/it4home.dk\/?p=72"},"modified":"2023-10-22T15:39:50","modified_gmt":"2023-10-22T13:39:50","slug":"setting-up-nfs-server-on-raspberry-pi","status":"publish","type":"post","link":"https:\/\/it4home.dk\/index.php\/2023\/08\/05\/setting-up-nfs-server-on-raspberry-pi\/","title":{"rendered":"Setting Up NFS Server on Raspberry Pi"},"content":{"rendered":"<div class=\"pdfprnt-buttons pdfprnt-buttons-post pdfprnt-top-right\"><a href=\"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/posts\/72?print=pdf\" class=\"pdfprnt-button pdfprnt-button-pdf\" target=\"_blank\" ><\/a><a href=\"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/posts\/72?print=print\" class=\"pdfprnt-button pdfprnt-button-print\" target=\"_blank\" ><img decoding=\"async\" src=\"https:\/\/it4home.dk\/wp-content\/plugins\/pdf-print\/images\/print.png\" alt=\"image_print\" title=\"Print Content\" \/><\/a><\/div>\n<p class=\"wp-block-paragraph\">Introduction:<br>NFS (Network File System) allows you to share directories and files between systems over a network. In this guide, we&#8217;ll walk you through setting up an NFS server on your Raspberry Pi and sharing a directory with other systems.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Step 1: Install NFS Server<br>To install the NFS server package, run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt-get install nfs-kernel-server -y<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Step 2: Create the NFS Share Directory<br>Next, create a directory that you want to share with other systems. In this example, we&#8217;ll use <code>\/mnt\/nfsshare<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mkdir \/mnt\/nfsshare<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Step 3: Set Permissions for the NFS Share<br>For the NFS share to be accessible, we need to set appropriate permissions on the shared directory. In this example, we&#8217;ll set the permissions to allow everyone full access. Note that this configuration might not be suitable for production systems.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo chmod 777 \/mnt\/nfsshare<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Step 4: Configure the NFS Export<br>Open the <code>\/etc\/exports<\/code> file in a text editor:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo vi \/etc\/exports<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Insert the following line at the end of the file to define the NFS share:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/mnt\/nfsshare *(rw,no_root_squash,insecure,async,no_subtree_check,anonuid=1000,anongid=1000)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Explanation of the options used:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>*<\/code>: Allow any client to access the share.<\/li>\n\n\n\n<li><code>rw<\/code>: Allow read and write access to the share.<\/li>\n\n\n\n<li><code>no_root_squash<\/code>: Preserve the root user&#8217;s identity from the client-side (use with caution).<\/li>\n\n\n\n<li><code>insecure<\/code>: Allow the use of non-privileged ports for NFS.<\/li>\n\n\n\n<li><code>async<\/code>: Improve performance by allowing asynchronous writes to the shared directory.<\/li>\n\n\n\n<li><code>no_subtree_check<\/code>: Disable subtree checking to improve performance.<\/li>\n\n\n\n<li><code>anonuid=1000<\/code> and <code>anongid=1000<\/code>: Map the anonymous user to the UID and GID 1000, which typically represents the first regular user on most systems.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Step 5: Activate the NFS Export<br>After modifying the <code>\/etc\/exports<\/code> file, apply the changes using the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo exportfs -ra<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Step 6: Start NFS Services<br>Start the NFS services to make the shared directory accessible:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl start nfs-kernel-server<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Step 7: Enable NFS Services on Boot<br>To ensure the NFS services start automatically on boot, enable them with the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl enable nfs-kernel-server<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Conclusion:<br>Congratulations! You have successfully set up an NFS server on your Raspberry Pi. The <code>\/mnt\/nfsshare<\/code> directory is now shared with other systems on the network. You can access this NFS share from other machines using the appropriate mount command.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Please note that for production environments or when sharing with specific clients, you should consider setting more secure and restricted permissions in the <code>\/etc\/exports<\/code> file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Happy sharing!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction:NFS (Network File System) allows you to share directories and files between systems over a network. In this guide, we&#8217;ll walk you through setting up an NFS server on your Raspberry Pi and sharing&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":363,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[5,7],"tags":[35],"class_list":["post-72","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-raspberry","tag-ok"],"_links":{"self":[{"href":"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/posts\/72","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/comments?post=72"}],"version-history":[{"count":2,"href":"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/posts\/72\/revisions"}],"predecessor-version":[{"id":139,"href":"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/posts\/72\/revisions\/139"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/media\/363"}],"wp:attachment":[{"href":"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/media?parent=72"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/categories?post=72"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/tags?post=72"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}