{"id":707,"date":"2016-02-04T14:07:06","date_gmt":"2016-02-04T14:07:06","guid":{"rendered":"https:\/\/blog.ngocha.biz\/?p=707"},"modified":"2016-02-04T14:07:06","modified_gmt":"2016-02-04T14:07:06","slug":"how-to-set-up-a-nfs-server-and-client","status":"publish","type":"post","link":"https:\/\/blog.ngocha.biz\/?p=707","title":{"rendered":"How To Set Up a NFS Server and Client For File Sharing"},"content":{"rendered":"<p>In this tutorial, I will explain how to set up an NFS server and client configurations for mounting an NFS share across systems in a network.[alert style=&#8221;e.g. white,<\/p>\n<p>[alert style=&#8221;e.g. white, grey, red, yellow, green&#8221;] Note: This tutorial is based on Ubuntu 14.04 server. You can create a VM easily on the cloud or using vagrant. [\/alert]<\/p>\n<h2 id=\"setup-an-nfs-server\">Setup an NFS server<\/h2>\n<p>In this setup, I have a ubuntu server with IP address 192.168.0.2.<\/p>\n<ol>\n<li>Refresh the apt package index<\/li>\n<\/ol>\n<pre><code>sudo apt-get update<\/code><\/pre>\n<ol start=\"2\">\n<li>Install the NFS package.<\/li>\n<\/ol>\n<pre><code>sudo apt-get install nfs-kernel-server<\/code><\/pre>\n<ol start=\"3\">\n<li>Next, we need to create a directory that can be shared with other hosts in the network. I am going to create a folder in var directory.<\/li>\n<\/ol>\n<pre><code>sudo mkdir \/var\/nfs<\/code><\/pre>\n<ol start=\"4\">\n<li>Change the ownership of the NFS folder to&nbsp;<a href=\"https:\/\/en.wikipedia.org\/wiki\/Nobody_(username)?ref=devopscube.com\" rel=\"noopener\">\u201cnobody\u201d<\/a>&nbsp;and \u201cnogroup\u201d.<\/li>\n<\/ol>\n<pre><code>sudo chown nobody:nogroup \/var\/nfs<\/code><\/pre>\n<p>The &#8220;nobody&#8221; is a user present in most of the Linux distros which belong to the &#8220;nogroup&#8221; which does not have any privileges on the system programs or files.<\/p>\n<ol start=\"5\">\n<li>All the NFS configurations are set in the \/etc\/exports file. In which we can give specific permissions for a client to access the files in the share.<\/li>\n<\/ol>\n<p>In this example, I have a client with IP 192.168.0.3. Open the exports file and make an entry as shown below.<\/p>\n<pre><code>\/var\/nfs    192.168.0.3(rw,sync,no_subtree_check)<\/code><\/pre>\n<ol start=\"6\">\n<li>NFS table holds all the exports of the shares. You can create one using the following command.<\/li>\n<\/ol>\n<pre><code>sudo exportfs -a<\/code><\/pre>\n<ol start=\"7\">\n<li>Now, let\u2019s start the NFS service.<\/li>\n<\/ol>\n<pre><code>sudo service nfs-kernel-server start<\/code><\/pre>\n<p>That&#8217;s it! We have an NFS server up and running.<\/p>\n<h2 id=\"setup-nfs-client-node\">Setup NFS client Node<\/h2>\n<p>All the servers which need access to the NFS share need to install the NFS client packages.<\/p>\n<ol>\n<li>Refresh the apt list and install the client package.<\/li>\n<\/ol>\n<pre><code>sudo apt-get update \nsudo apt-get install nfs-common<\/code><\/pre>\n<ol start=\"2\">\n<li>Let\u2019s create a folder that will be mounted to the remote NFS share.<\/li>\n<\/ol>\n<pre><code>sudo mkdir \/mnt\/nfs\/<\/code><\/pre>\n<ol start=\"3\">\n<li>Now, mount the remote NFS directory with out local \/mnt\/nfs directory.<\/li>\n<\/ol>\n<pre><code>sudo mount 192.168.0.2:\/var\/nfs  \/mnt\/nfs<\/code><\/pre>\n<ol start=\"4\">\n<li>Verify the mount using the following command. You will see NFS share listed in the file system.<\/li>\n<\/ol>\n<pre><code>df -h<\/code><\/pre>\n<p>The output looks like the following.<\/p>\n<pre><code>192.168.0.2:\/var\/nfs   40G  1.4G   37G   4% \/mnt\/nfs<\/code><\/pre>\n<ol start=\"5\">\n<li>Now you can test the share by creating a test file in \/var\/nfs folder of the NFS server and try to list that in your clients \/mnt\/nfs folder.<\/li>\n<\/ol>\n<p>That&#8217;s it! You now have an NFS share server and client up and running. You can add more clients in the same way we set up our first client.<\/p>\n<hr>\n<p><strong>Ngu\u1ed3n:<\/strong> <a href=\"https:\/\/devopscube.com\/how-to-set-up-a-nfs-server-and-client\/\" target=\"_blank\" rel=\"noopener noreferrer\">How To Set Up a NFS Server and Client For File Sharing \u2014 DevOpsCube<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Source: https:\/\/devopscube.com\/how-to-set-up-a-nfs-server-and-client\/<\/p>\n","protected":false},"author":1,"featured_media":708,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-707","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops"],"_links":{"self":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/707","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=707"}],"version-history":[{"count":0,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/707\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/media\/708"}],"wp:attachment":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=707"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=707"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=707"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}