<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Seventh Sense &#187; NFS</title>
	<atom:link href="http://sgowtham.net/blog/category/technology/nfs/feed/" rel="self" type="application/rss+xml" />
	<link>http://sgowtham.net/blog</link>
	<description>Rambling about life&#039;s little things, in 7 ≡ 1 (mod 6) fashion</description>
	<lastBuildDate>Tue, 28 Feb 2012 23:25:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<image>
	<title>Seventh Sense</title>
	<url>http://sgowtham.net/images/sg_logo_rss.png</url>
	<link>http://sgowtham.net/blog</link>
	<width>32</width>
	<height>32</height>
	</image>
		<item>
		<title>NFS : Server &amp; Client Set Up With AutoFS</title>
		<link>http://sgowtham.net/blog/2007/11/14/nfs-server-client-set-up-with-autofs/</link>
		<comments>http://sgowtham.net/blog/2007/11/14/nfs-server-client-set-up-with-autofs/#comments</comments>
		<pubDate>Wed, 14 Nov 2007 14:30:40 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[NFS]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/2007/11/14/nfs-server-client-set-up-with-autofs/</guid>
		<description><![CDATA[Disclaimer There are very many options that can be used while exporting and mounting NFS partitions as well as while custom-configuring the firewall with IPTABLES. Please read through the man pages to see what fits best. Below given instructions are what I used to set up NFS within my internal network and these may very [...]]]></description>
			<content:encoded><![CDATA[<h3 class="blog">Disclaimer</h3>
<p>There are very many options that can be used while exporting and mounting NFS partitions as well as while custom-configuring the firewall with IPTABLES. Please read through the <tt>man</tt> pages to see what fits best. Below given instructions are what I used to set up NFS within my internal network and these may very well work for you. However, please note that you are using these instructions at your very own risk and this website, <a href="http://sgowtham.net/" target="_blank">sgowtham.net</a>, is not responsible for any/all damage caused to your property, intellectual or otherwise.</p>
<p><br clear="all"><br />
It is not uncommon to find people (or organizations) who have multiple computers at their disposal and more often than not, these people (or organizations) find themselves in following situation:</p>
<blockquote><p>One of these machines, often pretty powerful, contains data that need to be accessed from one or more of the other machines.</p></blockquote>
<p>As is the case with most problems, there exists more than one way to solve this issue. This article discusses, in step-by-step fashion, one such possible approach &#8211; Network File System (abbreviated as NFS) &#8211; as applicable to Red Hat Enterprise Linux distributions. But unlike the <a href="http://sgowtham.net/blog/2007/11/09/nfs-server-client-set-up/" target="_blank">previous write-up</a> along similar lines, this one makes use of <tt>autofs</tt> service on client machines, so that the NFS shares are mounted on demand and are automatically unmounted when they are not being used. Few more suggestions from buddy <a href="http://bigmaninjapan.com/" target="_blank">Chong</a> have also been incorporated to improve the performance.</p>
<p><br clear="all"></p>
<h3 class="blog">What is NFS?</h3>
<p>According to Wikipedia, it is a network file system protocol originally developed by Sun Microsystems in 1984, allowing a user on a client computer to access files over a network as easily as if the network devices were attached to its local disks. NFS, like many other protocols, builds on the <em>Open Network Computing Remote Procedure Call</em> (ONC RPC) system. The Network File System protocol is specified in <a href="http://tools.ietf.org/html/rfc1094" target="_blank">RFC 1094</a>, <a href="http://tools.ietf.org/html/rfc1813" target="_blank">RFC 1813</a>, and <a href="http://tools.ietf.org/html/rfc3530" target="_blank">RFC 3530</a>.</p>
<p><br clear="all"></p>
<h3 class="blog">The Server Part</h3>
<ol>
<li>Let us assume that the IP address of the server is 192.168.1.2</li>
<li>Login as <b>root</b></li>
<li>Decide on two things:
<ol>
<li>What file systems should be made available to clients? Let us assume that <tt>/usr/local</tt> (as read only) and <tt>/home</tt> (as read/write) partitions need to be exported.</li>
<li>Which machines/clients (IP range or specific hostnames) should be allowed to access the exported file systems? Let us assume that all machines in the internal network &#8211; identified by IP addresses 192.168.1.xxx/255.255.255.0 &#8211; should have access to the exported partitions.</li>
</ol>
</li>
<li>Once the above is determined, this information needs to be put in a file that NFS will look up and do the needful. Add the following to <tt>/etc/exports</tt>:

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="dot" style="font-family:monospace;"><span style="color: #339933;"># /etc/exports</span>
<span style="color: #66cc66;">/</span>usr<span style="color: #66cc66;">/</span><span style="color: #993333;">local</span>      192.168.1.0<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">24</span><span style="color: #66cc66;">&#40;</span>ro,async<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">/</span>home          192.168.1.0<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">24</span><span style="color: #66cc66;">&#40;</span>rw,async<span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

</li>
<li>Save and close the file, Run the following command:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">exportfs <span style="color: #660033;">-rva</span></pre></div></div>

</li>
<li>Assuming that a full/complete/maximum installation of the linux distribution was done, start the NFS service:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>nfs start</pre></div></div>

</li>
<li>If you plan on keeping this service active over reboots, then:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">chkconfig - <span style="color: #660033;">-level</span> <span style="color: #000000;">345</span> nfs on</pre></div></div>

</li>
</ol>
<p><br clear="all"></p>
<h3 class="blog">The Client Part &#8211; With AutoFS</h3>
<ol>
<li>Login as <b>root</b></li>
<li>Autofs uses the <tt>automount</tt> daemon to manage your mount points by only mounting them dynamically when they are accessed. Autofs consults the master map configuration file <tt>/etc/auto.master</tt> to determine which mount points are defined. It then starts an <tt>automount</tt> process with the appropriate parameters for each mount point. Each line in the master map defines a mount point and a separate map file that defines the filesystems to be mounted under this mount point. For example, the <tt>/etc/auto.misc</tt> file might define mount points in the <tt>/misc</tt> directory; this relationship would be defined in the <tt>/etc/auto.master</tt> file.
<p>Each entry in <tt>auto.master</tt> has three fields. The first field is the mount point. The second field is the location of the map file, and the third field is optional (can contain information such as a timeout value).</li>
<li>To mount the exported partitions under the mount point <tt>/misc/</tt>, add the following line to auto.master:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>misc   <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>auto.misc <span style="color: #660033;">--timeout</span> <span style="color: #000000;">60</span></pre></div></div>

<p>The directory <tt>/misc</tt> must exist on the local filesystem (it does exist on most Red Hat Linux distributions). There should be <b>no</b> subdirectories in <tt>/misc</tt> on the local filesystem.</li>
<li>Add the following line to <tt>/etc/auto.misc</tt>:

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="dot" style="font-family:monospace;"><span style="color: #cc66cc;">192</span>_168_1_2_usr_local <span style="color: #66cc66;">-</span>ro,soft,intr,rsize<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">8192</span>,wsize<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">8192</span>   192.168.1.2:<span style="color: #66cc66;">/</span>usr<span style="color: #66cc66;">/</span><span style="color: #993333;">local</span>
<span style="color: #cc66cc;">192</span>_168_1_2_home  <span style="color: #66cc66;">-</span>rw,soft,intr,rsize<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">8192</span>,wsize<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">8192</span>   192.168.1.2:<span style="color: #66cc66;">/</span>home</pre></td></tr></table></div>

<p>The first field in <tt>/etc/auto.misc</tt> is the name of the /misc subdirectory. This directory is created <b>dynamically</b> by <tt>automount</tt>. It should not actually exist on the client machine. The second field contains mount options. The third field is the location of the NFS export including the hostname and directory.</li>
<li>Once the above is done, start the AutoFS service:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>autofs restart</pre></div></div>

</li>
<li>If you plan on keeping this set up active over reboots, then run:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">chkconfig - <span style="color: #660033;">-level</span> <span style="color: #000000;">345</span> autofs on</pre></div></div>

</li>
<li>If you modify the <tt>/etc/auto.master</tt> configuration file while <tt>autofs</tt> is running, the <tt>automount</tt> daemon(s) must be notified to reload by typing the following command at a shell prompt:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>service autofs reload</pre></div></div>

</li>
<li>To access the mounted NFS partition,

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>misc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">192</span>_168_1_2_home</pre></div></div>

<p>(or something similar) &#8211; <tt>192_168_1_2_home</tt> folder as well as its content will automagically show up.</li>
</ol>
<p><br clear="all"></p>
<h3 class="blog">Troubleshooting</h3>
<p>In spite of rigorously following the above steps (some of which were adopted from the Red Hat documentation), I could not proceed beyond</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>autofs restart</pre></div></div>

<p> stage &#8211; it would just fail and repetitively so. Fortunately, the troubleshooting I did for the previous entry solved this one as well. For completeness sake, here it is: First thing I had to check was to make sure I was using the proper syntax (in commands) and appropriate arguments/options for a given command. Since the error was very easily reproducible, I thought SELinux (Security Enhanced Linux) feature might be obstructing proper functioning of NFS and as such, I disabled it. As <b>root</b>, I edited the <tt>/etc/sysconfig/selinux</tt> (in server as well as client) and made it look like:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># This file controls the state of SELinux on the system.</span>
<span style="color: #666666; font-style: italic;"># SELINUX= can take one of these three values:</span>
<span style="color: #666666; font-style: italic;">#       enforcing - SELinux security policy is enforced.</span>
<span style="color: #666666; font-style: italic;">#       permissive - SELinux prints warnings instead of enforcing.</span>
<span style="color: #666666; font-style: italic;">#       disabled - SELinux is fully disabled.</span>
<span style="color: #007800;">SELINUX</span>=disabled
<span style="color: #666666; font-style: italic;"># SELINUXTYPE= type of policy in use. Possible values are:</span>
<span style="color: #666666; font-style: italic;">#       targeted - Only targeted network daemons are protected.</span>
<span style="color: #666666; font-style: italic;">#       strict - Full SELinux protection.</span>
<span style="color: #666666; font-style: italic;"># SELINUXTYPE=targeted</span></pre></td></tr></table></div>

<p>After rebooting (both server and client) and re-attempting the NFS set up, I still got the same error message &#8211; meaning, something else was obstructing the process. A little bit of digging around and Google!ng led me to believe that the default firewall rules in the server were the culprit. The following steps were followed to resolve this issue:</p>
<ol>
<li>Login as <strong>root</strong> on the server (192.168.1.2)</li>
<li>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>sysconfig<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">cp</span> iptables iptables.default
<span style="color: #7a0874; font-weight: bold;">cd</span></pre></div></div>

</li>
<li>Based on firewall rules implemented in a beowulf linux cluster, I created a file called <tt>custom_firewall.sh</tt>, with following contents:

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/bash</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Define a local variable, IPTABLES</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">IPTABLES</span>=<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>iptables
&nbsp;
<span style="color: #666666; font-style: italic;"># Flush out all existing rules</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-F</span> INPUT
&nbsp;
<span style="color: #666666; font-style: italic;"># Set default Policy for Input, Output and Forward chains</span>
<span style="color: #666666; font-style: italic;"># If nothing else matches, these are followed</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-P</span> INPUT   ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-P</span> OUTPUT  ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-P</span> FORWARD DROP
&nbsp;
<span style="color: #666666; font-style: italic;"># Allow self-access by loopback interface</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT  <span style="color: #660033;">-i</span> lo <span style="color: #660033;">-p</span> all <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-o</span> lo <span style="color: #660033;">-p</span> all <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
<span style="color: #666666; font-style: italic;"># Accept established connections</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> eth0 <span style="color: #660033;">-p</span> tcp  <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> ESTABLISHED <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> eth0 <span style="color: #660033;">-p</span> udp  <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> ESTABLISHED <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> eth0 <span style="color: #660033;">-p</span> icmp <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> ESTABLISHED <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
<span style="color: #666666; font-style: italic;"># Ping requests</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> icmp <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
<span style="color: #666666; font-style: italic;"># FTP requests - not secure enough</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">20</span> <span style="color: #660033;">-j</span> DROP
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">21</span> <span style="color: #660033;">-j</span> DROP
&nbsp;
<span style="color: #666666; font-style: italic;"># TelNet requests - not secure enough</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">23</span> <span style="color: #660033;">-j</span> DROP
&nbsp;
<span style="color: #666666; font-style: italic;"># HTTP requests</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">443</span> <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
<span style="color: #666666; font-style: italic;"># SSH requests - allows ssh, scp and sftp requests</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">22</span> <span style="color: #660033;">-s</span> 192.168.1.0<span style="color: #000000; font-weight: bold;">/</span>255.255.255.0  <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
<span style="color: #666666; font-style: italic;"># If more than 5 packets are dropped in 3 seconds they will be ignored</span>
<span style="color: #666666; font-style: italic;"># Helps to prevent a DOS attack crashing the computer</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span>second <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">5</span> <span style="color: #660033;">-i</span> <span style="color: #000000; font-weight: bold;">!</span> lo <span style="color: #660033;">-j</span> LOG
&nbsp;
<span style="color: #666666; font-style: italic;"># NFS</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> nfs <span style="color: #660033;">-s</span> 192.168.1.0<span style="color: #000000; font-weight: bold;">/</span>255.255.255.0 <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> udp <span style="color: #660033;">--dport</span> nfs <span style="color: #660033;">-s</span> 192.168.1.0<span style="color: #000000; font-weight: bold;">/</span>255.255.255.0 <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">111</span> <span style="color: #660033;">-s</span> 192.168.1.0<span style="color: #000000; font-weight: bold;">/</span>255.255.255.0 <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> ESTABLISHED,RELATED <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
<span style="color: #666666; font-style: italic;"># Keep track of log in attempts - /var/log/messages</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT  <span style="color: #660033;">-j</span> LOG <span style="color: #660033;">--log-prefix</span> <span style="color: #ff0000;">&quot;INPUT_DROP: &quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-j</span> LOG <span style="color: #660033;">--log-prefix</span> <span style="color: #ff0000;">&quot;OUTPUT_DROP: &quot;</span></pre></td></tr></table></div>

</li>
<li>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">700</span> custom_firewall.sh</pre></div></div>

</li>
<li>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>custom_firewall.sh</pre></div></div>

</li>
<li>To keep these rules intact over reboots,

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>service iptables save</pre></div></div>

</li>
</ol>
<p>After these steps, my attempt to set up NFS (both server and client with AutoFS) worked just fine. I understand my options for NFS as well as the firewall rules are neither comprehensive nor complete. As such, I (as well as others) would very much appreciate any thoughts to improve them.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsgowtham.net%2Fblog%2F2007%2F11%2F14%2Fnfs-server-client-set-up-with-autofs%2F&amp;title=NFS%20%3A%20Server%20%26%23038%3B%20Client%20Set%20Up%20With%20AutoFS" id="wpa2a_2"><img src="http://sgowtham.net/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2007/11/14/nfs-server-client-set-up-with-autofs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>NFS : Server &amp; Client Set Up</title>
		<link>http://sgowtham.net/blog/2007/11/09/nfs-server-client-set-up/</link>
		<comments>http://sgowtham.net/blog/2007/11/09/nfs-server-client-set-up/#comments</comments>
		<pubDate>Fri, 09 Nov 2007 22:08:49 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[NFS]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/2007/11/09/nfs-server-client-set-up/</guid>
		<description><![CDATA[Disclaimer There are very many options that can be used while exporting and mounting NFS partitions as well as while custom-configuring the firewall with IPTABLES. Please read through the man pages to see what fits best. Below given instructions are what I used to set up NFS within my internal network and these may very [...]]]></description>
			<content:encoded><![CDATA[<h3 class="blog">Disclaimer</h3>
<p>There are very many options that can be used while exporting and mounting NFS partitions as well as while custom-configuring the firewall with IPTABLES. Please read through the <tt>man</tt> pages to see what fits best. Below given instructions are what I used to set up NFS within my internal network and these may very well work for you. However, please note that you are using these instructions at your very own risk and this website, <a href="http://sgowtham.net/" target="_blank">sgowtham.net</a>, is not responsible for any/all damage caused to your property, intellectual or otherwise.</p>
<p><br clear="all"><br />
It is not uncommon to find people (or organizations) who have multiple computers at their disposal and more often than not, these people (or organizations) find themselves in following situation:</p>
<blockquote><p>One of these machines, often pretty powerful, contains data that need to be accessed from one or more of the other machines.</p></blockquote>
<p>As is the case with most problems, there exists more than one way to solve this issue. This article discusses, in step-by-step fashion, one such possible approach &#8211; Network File System (abbreviated as NFS) &#8211; as applicable to Red Hat Enterprise Linux distributions.</p>
<p><br clear="all"></p>
<h3 class="blog">What is NFS?</h3>
<p>According to Wikipedia, it is a network file system protocol originally developed by Sun Microsystems in 1984, allowing a user on a client computer to access files over a network as easily as if the network devices were attached to its local disks. NFS, like many other protocols, builds on the <em>Open Network Computing Remote Procedure Call</em> (ONC RPC) system. The Network File System protocol is specified in <a href="http://tools.ietf.org/html/rfc1094" target="_blank">RFC 1094</a>, <a href="http://tools.ietf.org/html/rfc1813" target="_blank">RFC 1813</a>, and <a href="http://tools.ietf.org/html/rfc3530" target="_blank">RFC 3530</a>.</p>
<p><br clear="all"></p>
<h3 class="blog">The Server Part</h3>
<ol>
<li>Let us assume that the IP address of the server is 192.168.1.2</li>
<li>Login as <b>root</b></li>
<li>Decide on two things:
<ol>
<li>What file systems should be made available to clients? Let us assume that <tt>/usr/local</tt> (as read only) and <tt>/home</tt> (as read/write) partitions need to be exported.</li>
<li>Which machines/clients (IP range or specific hostnames) should be allowed to access the exported file systems? Let us assume that all machines in the internal network &#8211; identified by IP addresses 192.168.1.xxx/255.255.255.0 &#8211; should have access to the exported partitions.</li>
</ol>
</li>
<li>Once the above is determined, this information needs to be put in a file that NFS will look up and do the needful. Add the following to <tt>/etc/exports</tt>:

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="dot" style="font-family:monospace;"><span style="color: #339933;"># /etc/exports</span>
<span style="color: #66cc66;">/</span>usr<span style="color: #66cc66;">/</span><span style="color: #993333;">local</span>      192.168.1.0<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">24</span><span style="color: #66cc66;">&#40;</span>ro,sync<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">/</span>home          192.168.1.0<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">24</span><span style="color: #66cc66;">&#40;</span>rw,sync<span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

</li>
<li>Save and close the file, Run the following command:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">exportfs <span style="color: #660033;">-rva</span></pre></div></div>

</li>
<li>Assuming that a full/complete/maximum installation of the linux distribution was done, start the NFS service:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>nfs start</pre></div></div>

</li>
<li>If you plan on keeping this service active over reboots, then:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">chkconfig - <span style="color: #660033;">-level</span> <span style="color: #000000;">345</span> nfs on</pre></div></div>

</li>
</ol>
<p><br clear="all"></p>
<h3 class="blog">The Client Part</h3>
<ol>
<li>Login as <b>root</b></li>
<li>Decide on the following:
<ol>
<li>Where will the exported file systems/partitions (from the Server) be mounted? Let us assume that <tt>/usr/local</tt> will be mounted at <tt>/mnt/192_168_1_2/usr_local</tt> (as read only) and <tt>/home</tt> will be mounted at <tt>/mnt/192_168_1_2/home</tt> (as read/write).</li>
<li>To that effect, create those mount points:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">192</span>_168_1_2<span style="color: #000000; font-weight: bold;">/</span>usr_local
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">192</span>_168_1_2<span style="color: #000000; font-weight: bold;">/</span>home</pre></div></div>

</li>
</ol>
</li>
<li>Once the above is done, mount the exported file systems:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #660033;">-t</span> nfs 192.168.1.2:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">192</span>_168_1_2<span style="color: #000000; font-weight: bold;">/</span>usr_local
<span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #660033;">-t</span> nfs 192.168.1.2:<span style="color: #000000; font-weight: bold;">/</span>home <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">192</span>_168_1_2<span style="color: #000000; font-weight: bold;">/</span>home</pre></div></div>

</li>
<li>If you plan on keeping this set up active over reboots, then add the following lines to <tt>/etc/fstab</tt>:

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="dot" style="font-family:monospace;">192.168.1.2:<span style="color: #66cc66;">/</span>usr<span style="color: #66cc66;">/</span><span style="color: #993333;">local</span> <span style="color: #66cc66;">/</span>mnt<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">192</span>_168_1_2<span style="color: #66cc66;">/</span>usr_local           nfs     ro,sync,timeo<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">14</span>,root_squash            <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span>
192.168.1.2:<span style="color: #66cc66;">/</span>home <span style="color: #66cc66;">/</span>mnt<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">192</span>_168_1_2<span style="color: #66cc66;">/</span>home           nfs     rw,sync,timeo<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">14</span>,root_squash              <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span></pre></td></tr></table></div>

</li>
<li>Save and close the file.</li>
</ol>
<p><br clear="all"></p>
<h3 class="blog">Troubleshooting</h3>
<p>One of the most common problems that bugged me for a while was the following: When</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #660033;">-t</span> nfs 192.168.1.2:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">192</span>_168_1_2<span style="color: #000000; font-weight: bold;">/</span>usr_local</pre></div></div>

<p>is executed on the client, it results in the following error:</p>
<p><tt><font color="#ff0000">mount: mount to NFS server '192.168.1.2' failed: System Error: No route to host.</font></tt></p>
<p>First thing I had to check was to make sure I was using the proper syntax (in commands) and appropriate arguments/options for a given command. Since the error was very easily reproducible, I thought SELinux (Security Enhanced Linux) feature might be obstructing proper functioning of NFS and as such, I disabled it. As <b>root</b>, I edited the <tt>/etc/sysconfig/selinux</tt> (in server as well as client) and made it look like:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># This file controls the state of SELinux on the system.</span>
<span style="color: #666666; font-style: italic;"># SELINUX= can take one of these three values:</span>
<span style="color: #666666; font-style: italic;">#       enforcing - SELinux security policy is enforced.</span>
<span style="color: #666666; font-style: italic;">#       permissive - SELinux prints warnings instead of enforcing.</span>
<span style="color: #666666; font-style: italic;">#       disabled - SELinux is fully disabled.</span>
<span style="color: #007800;">SELINUX</span>=disabled
<span style="color: #666666; font-style: italic;"># SELINUXTYPE= type of policy in use. Possible values are:</span>
<span style="color: #666666; font-style: italic;">#       targeted - Only targeted network daemons are protected.</span>
<span style="color: #666666; font-style: italic;">#       strict - Full SELinux protection.</span>
<span style="color: #666666; font-style: italic;"># SELINUXTYPE=targeted</span></pre></td></tr></table></div>

<p>After rebooting (both server and client) and re-attempting the NFS set up, I still got the same error message &#8211; meaning, something else was obstructing the process. A little bit of digging around and Google!ng led me to believe that the default firewall rules in the server were the culprit. The following steps were followed to resolve this issue:</p>
<ol>
<li>Login as <strong>root</strong> on the server (192.168.1.2)</li>
<li>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>sysconfig<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

</li>
<li>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cp</span> iptables iptables.default</pre></div></div>

</li>
<li>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span></pre></div></div>

</li>
<li>Based on firewall rules implemented in a beowulf linux cluster, I created a file called <tt>custom_firewall.sh</tt>, with following contents:

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/bash</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Define a local variable, IPTABLES</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">IPTABLES</span>=<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>iptables
&nbsp;
<span style="color: #666666; font-style: italic;"># Flush out all existing rules</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-F</span> INPUT
&nbsp;
<span style="color: #666666; font-style: italic;"># Set default Policy for Input, Output and Forward chains</span>
<span style="color: #666666; font-style: italic;"># If nothing else matches, these are followed</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-P</span> INPUT   ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-P</span> OUTPUT  ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-P</span> FORWARD DROP
&nbsp;
<span style="color: #666666; font-style: italic;"># Allow self-access by loopback interface</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT  <span style="color: #660033;">-i</span> lo <span style="color: #660033;">-p</span> all <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-o</span> lo <span style="color: #660033;">-p</span> all <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
<span style="color: #666666; font-style: italic;"># Accept established connections</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> eth0 <span style="color: #660033;">-p</span> tcp  <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> ESTABLISHED <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> eth0 <span style="color: #660033;">-p</span> udp  <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> ESTABLISHED <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> eth0 <span style="color: #660033;">-p</span> icmp <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> ESTABLISHED <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
<span style="color: #666666; font-style: italic;"># Ping requests</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> icmp <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
<span style="color: #666666; font-style: italic;"># FTP requests - not secure enough</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">20</span> <span style="color: #660033;">-j</span> DROP
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">21</span> <span style="color: #660033;">-j</span> DROP
&nbsp;
<span style="color: #666666; font-style: italic;"># TelNet requests - not secure enough</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">23</span> <span style="color: #660033;">-j</span> DROP
&nbsp;
<span style="color: #666666; font-style: italic;"># HTTP requests</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">443</span> <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
<span style="color: #666666; font-style: italic;"># SSH requests - allows ssh, scp and sftp requests</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">22</span> <span style="color: #660033;">-s</span> 192.168.1.0<span style="color: #000000; font-weight: bold;">/</span>255.255.255.0  <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
<span style="color: #666666; font-style: italic;"># If more than 5 packets are dropped in 3 seconds they will be ignored</span>
<span style="color: #666666; font-style: italic;"># Helps to prevent a DOS attack crashing the computer</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span>second <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">5</span> <span style="color: #660033;">-i</span> <span style="color: #000000; font-weight: bold;">!</span> lo <span style="color: #660033;">-j</span> LOG
&nbsp;
<span style="color: #666666; font-style: italic;"># NFS</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> nfs <span style="color: #660033;">-s</span> 192.168.1.0<span style="color: #000000; font-weight: bold;">/</span>255.255.255.0 <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> udp <span style="color: #660033;">--dport</span> nfs <span style="color: #660033;">-s</span> 192.168.1.0<span style="color: #000000; font-weight: bold;">/</span>255.255.255.0 <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">111</span> <span style="color: #660033;">-s</span> 192.168.1.0<span style="color: #000000; font-weight: bold;">/</span>255.255.255.0 <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> ESTABLISHED,RELATED <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
<span style="color: #666666; font-style: italic;"># Keep track of log in attempts - /var/log/messages</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT  <span style="color: #660033;">-j</span> LOG <span style="color: #660033;">--log-prefix</span> <span style="color: #ff0000;">&quot;INPUT_DROP: &quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-j</span> LOG <span style="color: #660033;">--log-prefix</span> <span style="color: #ff0000;">&quot;OUTPUT_DROP: &quot;</span></pre></td></tr></table></div>

</li>
<li>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">700</span> custom_firewall.sh</pre></div></div>

</li>
<li>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>custom_firewall.sh</pre></div></div>

</li>
<li>To keep these rules intact over reboots,

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>service iptables save</pre></div></div>

</li>
</ol>
<p>After these steps, my attempt to set up NFS (both server and client) worked just fine. I understand my options for NFS as well as the firewall rules are neither comprehensive nor complete. As such, I (as well as others) would very much appreciate any thoughts to improve them.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsgowtham.net%2Fblog%2F2007%2F11%2F09%2Fnfs-server-client-set-up%2F&amp;title=NFS%20%3A%20Server%20%26%23038%3B%20Client%20Set%20Up" id="wpa2a_4"><img src="http://sgowtham.net/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2007/11/09/nfs-server-client-set-up/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

