{"id":398,"date":"2014-08-06T21:37:59","date_gmt":"2014-08-06T21:37:59","guid":{"rendered":"https:\/\/www.nicktailor.com\/?p=398"},"modified":"2014-08-06T22:15:34","modified_gmt":"2014-08-06T22:15:34","slug":"how-to-setup-a-nfs-server","status":"publish","type":"post","link":"https:\/\/nicktailor.com\/tech-blog\/how-to-setup-a-nfs-server\/","title":{"rendered":"How to setup a NFS server on Debian"},"content":{"rendered":"<p><span style=\"text-decoration: underline;\"><strong>DEBIAN SETUP<\/strong><\/span><\/p>\n<p>Make sure you have NFS server support in your server&#8217;s kernel (kernel module named &#8220;knfsd.ko&#8221; under your \/lib\/modules\/uname -r\/ directory structure)<\/p>\n<p style=\"padding-left: 30px;\"><em><strong>$ grep NFSD \/boot\/config-`uname -r`<\/strong><\/em><\/p>\n<p>or similar (wherever you&#8217;ve stashed your config file, for example, perhaps in \/usr\/src\/linux\/.config.)<\/p>\n<p>There are at ltwo mainstream NFS server implementations that people use (excluding those implemented in Python and similar): one implemented in user space, which is slower however easier to debug, and the other implemented in kernel space, which is faster.\u00a0Below shows the setup of the kernel-space one. If you wish to use the user-space server, then install the similarly-named package.<\/p>\n<p>First, the packages to begin with:<\/p>\n<ol>\n<li>\u00a0<strong>$ aptitude install nfs-kernel-server portmap<\/strong><\/li>\n<\/ol>\n<p style=\"padding-left: 30px;\"><em> Note that portmap defaults to only listening for NFS connection attempts on 127.0.0.1 (localhost), so if you wish to allow connections on your local network, then you need to edit \/etc\/default\/portmap, to comment out the &#8220;OPTIONS&#8221; line. Also, we need to ensure that the \/etc\/hosts.allow file allows connections to the portmap port. For example:<\/em><\/p>\n<p>2. \u00a0 Now run the following commands. This will edit the portmap configuration file and all<br \/>\nthe subnet in your hosts.allow for which ever subnet is nfs server is on<\/p>\n<ul>\n<ul>\n<ul>\n<li><em>\u00a0 \u00a0 \u00a0 \u00a0 <strong>\u00a0 $ perl -pi -e &#8216;s\/^OPTIONS\/#OPTIONS\/&#8217; \/etc\/default\/portmap<\/strong><\/em><\/li>\n<li><strong><em>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 $ echo &#8220;portmap: 192.168.1.&#8221; &gt;&gt; \/etc\/hosts.allow<\/em><\/strong><\/li>\n<li><strong><em>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 $ \/etc\/init.d\/portmap restart\u00a0<\/em><\/strong><\/li>\n<li>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0<strong style=\"color: #000000; font-style: normal;\"><strong><em>$ echo &#8220;rpcbind: ALL&#8221; &gt;&gt; \/etc\/hosts.allow<br \/>\n<\/em><\/strong><\/strong><\/li>\n<\/ul>\n<\/ul>\n<\/ul>\n<p style=\"padding-left: 30px;\"><em>See &#8216;man hosts.allow&#8217; for examples on the syntax. But in general, specifying only part of the IP address like this (leaving the trailing period) treats the specified IP address fragment as a wildcard, allowing all IP addresses in the range 192.168.1.0 to 192.168.1.255 (in this example.) You can do more &#8220;wildcarding&#8221; using DNS names, and so on too.<\/em><\/p>\n<ol start=\"3\">\n<li>Then, edit the \/etc\/exports file, which lists the server&#8217;s filesystems to export over NFS to client machines. The following example shows the addition of a line which adds the path &#8220;\/example&#8221;, for access by any machine on the local network (here 192.168.1.*).<\/li>\n<\/ol>\n<ol start=\"4\">\n<li>\u00a0<strong><em>$ echo &#8220;\/example 192.168.1.0\/255.255.255.0(rw,no_root_squash,subtree_check)&#8221; &gt;&gt; \/etc\/exports<\/em><\/strong><\/li>\n<li>\u00a0<strong><em>$ \/etc\/init.d\/nfs-kernel-server reload<\/em><\/strong><\/li>\n<\/ol>\n<p><em> This tells the server to serve up that path, readable\/writable, with root-user-id connecting clients to use root access instead of being mapped to &#8216;nobody&#8217;, and to use the &#8216;subtree_check&#8217; to silence a warning message. Then, reloads the server.<br \/>\n<\/em><\/p>\n<p>6. On the Client server you wish to mount to the NFS share type the following<\/p>\n<ul>\n<ul>\n<li>$<strong style=\"color: #000000; font-style: normal;\"><em> mount 192.168.1.100:\/example \/mnt\/example<\/em><\/strong><\/li>\n<\/ul>\n<\/ul>\n<p><em>Result should look like this if you type <\/em><\/p>\n<ul>\n<ul>\n<li><strong><em style=\"color: #000000;\">$mount &lt;enter&gt;<\/em><\/strong><\/li>\n<\/ul>\n<\/ul>\n<p style=\"padding-left: 30px;\"><em>\/dev\/sda3 on \/ type ext4 (rw,errors=remount-ro)<\/em><br \/>\n<em>tmpfs on \/lib\/init\/rw type tmpfs (rw,nosuid,mode=0755)<\/em><br \/>\n<em>proc on \/proc type proc (rw,noexec,nosuid,nodev)<\/em><br \/>\n<em>sysfs on \/sys type sysfs (rw,noexec,nosuid,nodev)<\/em><br \/>\n<em>udev on \/dev type tmpfs (rw,mode=0755)<\/em><br \/>\n<em>tmpfs on \/dev\/shm type tmpfs (rw,nosuid,nodev)<\/em><br \/>\n<em>devpts on \/dev\/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)<\/em><br \/>\n<em>\/dev\/sda1 on \/tmp type ext4 (rw)<\/em><br \/>\n<em>rpc_pipefs on \/var\/lib\/nfs\/rpc_pipefs type rpc_pipefs (rw)<\/em><br \/>\n<em>nfsd on \/proc\/fs\/nfsd type nfsd (rw)<\/em><br \/>\n<strong><em>192.168.1.100:\/nicktest on \/mnt\/nfs type nfs (rw,nolock,addr=192.168.1.100)<\/em><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>DEBIAN SETUP Make sure you have NFS server support in your server&#8217;s kernel (kernel module named &#8220;knfsd.ko&#8221; under your \/lib\/modules\/uname -r\/ directory structure) $ grep NFSD \/boot\/config-`uname -r` or similar (wherever you&#8217;ve stashed your config file, for example, perhaps in \/usr\/src\/linux\/.config.) There are at ltwo mainstream NFS server implementations that people use (excluding those implemented in Python and similar): one<a href=\"https:\/\/nicktailor.com\/tech-blog\/how-to-setup-a-nfs-server\/\" class=\"read-more\">Read More &#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-398","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/posts\/398","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/comments?post=398"}],"version-history":[{"count":20,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/posts\/398\/revisions"}],"predecessor-version":[{"id":420,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/posts\/398\/revisions\/420"}],"wp:attachment":[{"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/media?parent=398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/categories?post=398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/tags?post=398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}