Wednesday, September 23, 2009

Configured NFS

If you shares files between Linux boxes one of the easiest ways to do this is by using NFS. I thought this quick guide for setting up an NFS network might be useful. This might not be the best or only way of doing it but this works for me.

Server Settings

First off you need to configure the machine that's going to act as the server by doing the following (you need to be root for this):

1. Install the NFS packages using yum:

Code:

yum install nfs-utils nfs-utils-lib portmap system-config-nfs



2. You now need to set up your /etc/exports file with details of the directory you want to share, who is allowed to share it, and permissions. So:

Code:

gedit /etc/exports



Then add an entry similar to the one below, and save and close:

Code:

 
/home/admin 192.168.2.30(rw,no_root_squash,sync)



The first part is the directory I want to share, the second the IP address of the client who is allowed to access the directory, and the part in brackets allows read/write access and root access on the server (the no_root_squash entry is optional)

Note: if you prefer a gui and you're using Fedora as a server you can configure the exports file from the Desktop>Administration>Server Settings>NFS menu.

3. Now edit your hosts.allow file:

Code:

gedit /etc/hosts.allow



Paste in the following but change the IP address to the IP address of the client who will be allowed to access the server, in my case 192.168.2.30

Code:

portmap: 10.0.0.49
lockd: 10.0.0.49
mountd: 10.0.0.49
rquotad: 10.0.0.49
statd: 10.0.0.49



Save and close.

If multiple clients can access the server separate IP addresses with commas.

4. Now edit your hosts.deny file:

Code:

gedit /etc/hosts.deny



Paste in the following:

Code:

portmap: ALL
lockd: ALL
mountd: ALL
rquotad: ALL
statd: ALL



This prevents all hosts not listed in hosts.allow from accessing the server.

5. Open the Desktop>Administration>Security Level and Firewall menu. Select the Firewall Options tab and open the "Other Ports" dialogue. Use the "add" button to add the following:

2049 UDP
2049 TCP
111 UDP
111 TCP

vi /etc/sysconfig/iptables

-A INPUT -i eth0 -p udp -m udp --dport 9091 -j ACCEPT

-A INPUT -i eth0 -p tcp -m tcp --dport 9091 -j ACCEPT

-A INPUT -i eth0 -p tcp -m tcp --dport 9090 -j ACCEPT

-A INPUT -i eth0 -p udp -m udp --dport 9090 -j ACCEPT

-A INPUT -i eth0 -p udp -m udp --dport 2049 -j ACCEPT

-A INPUT -i eth0 -p tcp -m tcp --dport 2049 -j ACCEPT

-A INPUT -i eth0 -p tcp -m tcp --dport 111 -j ACCEPT

-A INPUT -i eth0 -p udp -m udp --dport 111 -j ACCEPT


Click OK.

Note: if you run FC4 there's a blank line called other ports. Just enter 2049:tcp,2049:udp,111:tcp,111:udp and hit OK.

6. The next step is exporting the directories you want to share and starting the NFS services. To start the nfs services type the following command into a terminal (as root):

Auto start nfs service

chkconfig nfs on



Then export the directories from /etc/exports:

exportfs -ra



Reboot and the services will start automatically.

Client Settings

Setting up the client side of NFS is fairly straightforward. I'm not sure whether it's absolutely necessary to install all the NFS packages for the client but I always do, as I might want the client to act as a server if I'm working on another machine. So the steps I follow are:

1. Install NFS packages:

Code:

 
yum install nfs-utils nfs-utils-lib portmap system-config-nfs



2. Open the folowing ports in the firewall:

2049 UDP
2049 TCP
111 UDP
111 TCP


vi /etc/sysconfig/iptables

-A INPUT -i eth0 -p udp -m udp --dport 9091 -j ACCEPT

-A INPUT -i eth0 -p tcp -m tcp --dport 9091 -j ACCEPT

-A INPUT -i eth0 -p tcp -m tcp --dport 9090 -j ACCEPT

-A INPUT -i eth0 -p udp -m udp --dport 9090 -j ACCEPT

-A INPUT -i eth0 -p udp -m udp --dport 2049 -j ACCEPT

-A INPUT -i eth0 -p tcp -m tcp --dport 2049 -j ACCEPT

-A INPUT -i eth0 -p tcp -m tcp --dport 111 -j ACCEPT

-A INPUT -i eth0 -p udp -m udp --dport 111 -j ACCEPT

3. Create a mountpoint for the NFS share (as root):

Code:

mkdir /media/admin



and set permissions so that you can access this mount point as a user:

Code:

chmod 777 /media/admin



4. Add an entry to fstab:

Code:

 
gedit /etc/fstab



Paste an entry at the bottom of the file that looks something like this:

192.168.2.5:/home/admin         /media/admin    nfs     noauto,rw,user 0 0



The first part is the IP address of the server and the directory that will be accessed. Dont forget to adapt the entry for your settings.

Save and close gedit.

5. As root type:

mount /media/admin



7. Make sure you can see the running services on the server by typing:

Code:

rpcinfo -p 10.0.0.49 (the IP address of the server).  



If you can, move on to the next step.

6. To mount the share type:

mount /media/admin

0 comments:

Post a Comment