{"id":371,"date":"2018-04-20T01:27:34","date_gmt":"2018-04-20T01:27:34","guid":{"rendered":"http:\/\/linuxresellerwebhosting.in\/blog\/?p=371"},"modified":"2018-04-22T03:50:59","modified_gmt":"2018-04-22T03:50:59","slug":"easy-ways-to-setup-nfs-server-on-centos","status":"publish","type":"post","link":"https:\/\/linuxresellerwebhosting.in\/blog\/easy-ways-to-setup-nfs-server-on-centos\/","title":{"rendered":"Easy Ways to Setup NFS Server on CentOS"},"content":{"rendered":"<p>Hello,<\/p>\n<p>Today we are going to see about NFS sever. The Network File System (NFS) is a way of mounting Linux discs\/directories over a network. An NFS server can\u00a0<b>export<\/b>\u00a0one or more directories that can then be mounted on a remote Linux machine. Note, that if you need to\u00a0<b>mount<\/b>\u00a0a Linux filesystem on a Windows machine, you need to use Samba\/CIFS instead.<\/p>\n<h5><span class=\"ez-toc-section\" id=\"Benefits_of_NFS\"><\/span>Benefits of NFS<span class=\"ez-toc-section-end\"><\/span><\/h5><div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 ez-toc-wrap-left counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><ul class='ez-toc-list-level-5' ><li class='ez-toc-heading-level-5'><ul class='ez-toc-list-level-5' ><li class='ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/linuxresellerwebhosting.in\/blog\/easy-ways-to-setup-nfs-server-on-centos\/#Benefits_of_NFS\" >Benefits of NFS<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/linuxresellerwebhosting.in\/blog\/easy-ways-to-setup-nfs-server-on-centos\/#Important_Files_for_NFS_Configuration\" >Important Files for NFS Configuration<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/linuxresellerwebhosting.in\/blog\/easy-ways-to-setup-nfs-server-on-centos\/#Setup_and_Configure_NFS_Mounts_on_Linux_Server\" >Setup and Configure NFS Mounts on Linux Server<\/a><ul class='ez-toc-list-level-5' ><li class='ez-toc-heading-level-5'><ul class='ez-toc-list-level-5' ><li class='ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/linuxresellerwebhosting.in\/blog\/easy-ways-to-setup-nfs-server-on-centos\/#Installing_NFS_Server_and_NFS_Client\" >Installing NFS Server and NFS Client<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/linuxresellerwebhosting.in\/blog\/easy-ways-to-setup-nfs-server-on-centos\/#Setting_Up_the_NFS_Server\" >Setting Up the NFS Server<\/a><ul class='ez-toc-list-level-5' ><li class='ez-toc-heading-level-5'><ul class='ez-toc-list-level-5' ><li class='ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/linuxresellerwebhosting.in\/blog\/easy-ways-to-setup-nfs-server-on-centos\/#Configure_Export_directory\" >Configure Export directory<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/linuxresellerwebhosting.in\/blog\/easy-ways-to-setup-nfs-server-on-centos\/#NFS_Options\" >NFS Options<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/linuxresellerwebhosting.in\/blog\/easy-ways-to-setup-nfs-server-on-centos\/#Setting_Up_the_NFS_Client\" >Setting Up the NFS Client<\/a><ul class='ez-toc-list-level-5' ><li class='ez-toc-heading-level-5'><ul class='ez-toc-list-level-5' ><li class='ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/linuxresellerwebhosting.in\/blog\/easy-ways-to-setup-nfs-server-on-centos\/#Mount_Shared_Directories_on_NFS_Client\" >Mount Shared Directories on NFS Client<\/a><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n<ol>\n<li><strong>NFS<\/strong>\u00a0allows local access to remote files.<\/li>\n<li>It uses standard\u00a0<strong>client<\/strong>\/<strong>server<\/strong>\u00a0architecture for file sharing between all *<strong>nix<\/strong>\u00a0based machines.<\/li>\n<li>With\u00a0<strong>NFS<\/strong>\u00a0it is not necessary that both machines run on the same\u00a0<strong>OS<\/strong>.<\/li>\n<li>With the help of\u00a0<strong>NFS<\/strong>\u00a0we can configure\u00a0<strong>centralized storage<\/strong>\u00a0solutions.<\/li>\n<li>Users get their\u00a0<strong>data<\/strong>\u00a0irrespective of physical location.<\/li>\n<li>No manual\u00a0<strong>refresh<\/strong>\u00a0needed for new files.<\/li>\n<li>Newer version of\u00a0<strong>NFS<\/strong>\u00a0also supports\u00a0<strong>acl<\/strong>,\u00a0<strong>pseudo<\/strong>\u00a0root mounts.<\/li>\n<li>Can be secured with\u00a0<strong>Firewalls<\/strong>\u00a0and\u00a0<strong>Kerberos<\/strong>.<\/li>\n<\/ol>\n<h5><span class=\"ez-toc-section\" id=\"Important_Files_for_NFS_Configuration\"><\/span>Important Files for NFS Configuration<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<ol>\n<li><strong>\/etc\/exports<\/strong>\u00a0: Its a main configuration file of\u00a0<strong>NFS<\/strong>, all exported\u00a0<strong>files<\/strong>\u00a0and\u00a0<strong>directories<\/strong>\u00a0are defined in this file at the\u00a0<strong>NFS Server<\/strong>\u00a0end.<\/li>\n<li><strong>\/etc\/fstab<\/strong>\u00a0: To mount a\u00a0<strong>NFS directory<\/strong>\u00a0on your system across the\u00a0<strong>reboots<\/strong>, we need to make an entry in\u00a0<strong>\/etc\/fstab<\/strong>.<\/li>\n<li><strong>\/etc\/sysconfig\/nfs<\/strong>\u00a0: Configuration file of\u00a0<strong>NFS<\/strong>\u00a0to control on which port\u00a0<strong>rpc<\/strong>\u00a0and other services are\u00a0<strong>listening<\/strong>.<\/li>\n<\/ol>\n<h3><span class=\"ez-toc-section\" id=\"Setup_and_Configure_NFS_Mounts_on_Linux_Server\"><\/span>Setup and Configure NFS Mounts on Linux Server<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>To setup\u00a0<strong>NFS<\/strong>\u00a0mounts, we\u2019ll be needing at least two\u00a0<strong>Linux<\/strong>\/<strong>Unix<\/strong>\u00a0machines. Here in this tutorial, I\u2019ll be using two servers.<\/p>\n<ol>\n<li><strong>NFS Server<\/strong>: nfsserver.example.com with IP-<strong>103.14.X.X<\/strong><\/li>\n<li><strong>NFS Client<\/strong>\u00a0: nfsclient.example.com with IP-<strong>192.168.0.12<\/strong><\/li>\n<\/ol>\n<h5><span class=\"ez-toc-section\" id=\"Installing_NFS_Server_and_NFS_Client\"><\/span>Installing NFS Server and NFS Client<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<p>We need to install\u00a0<strong>NFS<\/strong>\u00a0packages on our\u00a0<strong>NFS Server<\/strong>\u00a0as well as on\u00a0<strong>NFS Client<\/strong>\u00a0machine. We can install it via \u201c<strong>yum<\/strong>\u201d (<strong>Red Hat<\/strong>\u00a0Linux)<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-373\" src=\"http:\/\/linuxresellerwebhosting.in\/blog\/wp-content\/uploads\/2018\/04\/package-300x20.png\" alt=\"\" width=\"705\" height=\"47\" srcset=\"https:\/\/linuxresellerwebhosting.in\/blog\/wp-content\/uploads\/2018\/04\/package-300x20.png 300w, https:\/\/linuxresellerwebhosting.in\/blog\/wp-content\/uploads\/2018\/04\/package-768x51.png 768w, https:\/\/linuxresellerwebhosting.in\/blog\/wp-content\/uploads\/2018\/04\/package-1024x68.png 1024w, https:\/\/linuxresellerwebhosting.in\/blog\/wp-content\/uploads\/2018\/04\/package.png 1061w\" sizes=\"auto, (max-width: 705px) 100vw, 705px\" \/><\/p>\n<p>After installing packages and starting services on both the machines, we need to configure both the machines for file sharing.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true\">[root@vps ~]# systemctl start nfs\r\n[root@vps ~]# systemctl enable nfs<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Setting_Up_the_NFS_Server\"><\/span>Setting Up the NFS Server<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>First we will be configuring the\u00a0<strong>NFS<\/strong>\u00a0server.<\/p>\n<h5><span class=\"ez-toc-section\" id=\"Configure_Export_directory\"><\/span>Configure Export directory<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<p>For sharing a directory with\u00a0<strong>NFS<\/strong>, we need to make an entry in \u201c<strong>\/etc\/exports<\/strong>\u201d configuration file. Here I\u2019ll be creating a new directory named \u201cs<strong>hare<\/strong>\u201d in \u201c<strong>\/<\/strong>\u201d partition to share with\u00a0<strong>client server<\/strong>, you can also share an already existing directory with NFS.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true\">[root@vps ~]# mkdir \/share<\/pre>\n<p>Now we need to make an entry in \u201c<strong>\/etc\/exports<\/strong>\u201d and\u00a0<strong>restart<\/strong>\u00a0the services to make our directory shareable in the network.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true\">[root@vps ~]# echo \"\/share 192.168.0.12(rw,ro,sync, no_root_squash)\"  &gt;  \/etc\/exports<\/pre>\n<h5><span class=\"ez-toc-section\" id=\"NFS_Options\"><\/span>NFS Options<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<p>Some other options we can use in \u201c<strong>\/etc\/exports<\/strong>\u201d file for file sharing is as follows.<\/p>\n<ol>\n<li><strong>ro<\/strong>: With the help of this option we can provide\u00a0<strong>read only access<\/strong>\u00a0to the shared files i.e\u00a0<strong>client<\/strong>\u00a0will only be able to\u00a0<strong>read<\/strong>.<\/li>\n<li><strong>rw<\/strong>: This option allows the\u00a0<strong>client server<\/strong>\u00a0to both\u00a0<strong>read<\/strong>\u00a0and\u00a0<strong>write<\/strong>\u00a0access within the shared directory.<\/li>\n<li><strong>sync<\/strong>: Sync confirms requests to the shared directory only once the\u00a0<strong>changes<\/strong>\u00a0have been committed.<\/li>\n<li><strong>no_subtree_check<\/strong>: This option prevents the\u00a0<strong>subtree<\/strong>\u00a0checking. When a shared directory is the subdirectory of a larger file system,\u00a0<strong>nfs<\/strong>\u00a0performs scans of every directory above it, in order to verify its permissions and details. Disabling the\u00a0<strong>subtree<\/strong>\u00a0check may increase the reliability of\u00a0<strong>NFS<\/strong>, but reduce\u00a0<strong>security<\/strong>.<\/li>\n<li><strong>no_root_squash<\/strong>: This phrase allows\u00a0<strong>root<\/strong>\u00a0to\u00a0<strong>connect<\/strong>\u00a0to the designated directory.<\/li>\n<\/ol>\n<h3><span class=\"ez-toc-section\" id=\"Setting_Up_the_NFS_Client\"><\/span>Setting Up the NFS Client<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>After configuring the\u00a0<strong>NFS<\/strong>\u00a0server, we need to\u00a0<strong>mount<\/strong>\u00a0that shared directory or partition in the\u00a0<strong>client<\/strong>\u00a0server.<\/p>\n<h5><span class=\"ez-toc-section\" id=\"Mount_Shared_Directories_on_NFS_Client\"><\/span>Mount Shared Directories on NFS Client<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<p>Now at the\u00a0<strong>NFS client<\/strong>\u00a0end, we need to\u00a0<strong>mount<\/strong>\u00a0that directory in our server to access it locally. To do so, first we need to find out that shares available on the remote server or NFS Server.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true\">[root@vps ~]# showmount -e 103.14.121.87\r\nExport list for 103.14.121.87:\r\n\/share 192.168.0.12<\/pre>\n<p>To\u00a0<strong>mount<\/strong>\u00a0that shared\u00a0<strong>NFS<\/strong>\u00a0directory we can use following mount command.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# mount -t nfs 103.14.x.x:\/share \/mnt<\/pre>\n<p>The above mount command mounted the\u00a0<strong>nfs shared directory<\/strong>\u00a0on to\u00a0<strong>nfs client<\/strong>\u00a0temporarily, to mount an NFS directory\u00a0<strong>permanently<\/strong>\u00a0on your system across the\u00a0<strong>reboots<\/strong>, we need to make an entry in \u201c<strong>\/etc\/fstab<\/strong>\u201c.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# vi \/etc\/fstab<\/pre>\n<p>Add the following new line as shown below.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true\">103.14.x.x nfs \/mnt defaults 0 0<\/pre>\n<p>Now you have successfully configured NFS Server \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello, Today we are going to see about NFS sever. The Network File System (NFS) is a way of mounting<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[1],"tags":[],"class_list":["post-371","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/371","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/comments?post=371"}],"version-history":[{"count":3,"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/371\/revisions"}],"predecessor-version":[{"id":375,"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/371\/revisions\/375"}],"wp:attachment":[{"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/media?parent=371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/categories?post=371"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/tags?post=371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}