Tuesday, November 10, 2009

Setting up NFS server

Though using samba may work really well sometimes you may like to have a more native linux solution for sharing files. A situation, where I would use NFS rather than Samba is a sharing between two linux computers.

First you will have to install a package providing nfs server on your system. On ubuntu or debian I would do that by

apt-get install nfs-kernel-server

Now, assuming that you have an NFS daemon installed it's time for configuring it. The configuration in stored in /etc/exports file and should look like this, when you open it:


# /etc/exports: the access control list for filesystems which may be exported
# to NFS clients. See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes hostname1(rw,sync,no_subtree_check) 
#
# Example for NFSv4:
# /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check)

Every single line in this file will create a new exported (shared) folder. Let's imagine, that you would like to make folder /sharing available to all computers in your local network. This is achieved by this line:

/sharing 10.0.0.0/24(rw,sync,no_subtree_check)

As you can see the syntax is really easy. First you specify the folder, you would like to export, and then the host, that will have access to this share. I have specified an ip address and a mask, which will allow access to all computers with ip range from 10.0.0.1-10.0.0.255. The ip address is specified in a format of address/mask. The mask may be written in both formats(255.255.255.0,24)-You can specify a hostname, or a domain as well. Setting * will allow access to anyone.

All other options are specified inside parenthesis right after the allowed clients. Let's specify at least the most important ones.

  • ro - read only
  • rw - read and write
  • sync - reply to requests only after the changes have been committed to stable storage
  • no_subtree_check - disables subtree check
  • root_squash - maps requests from uid 0 to anonymous user
  • no_root_squash - turns off root squashing - will access all files as root
  • all_squash - maps all users to anonymous user

I know, that some explanations aren't absolutely clear. You may have a look at man exports for more detailed description.

Every time you finish altering /etc/exports you must execute this:

exportfs -a

After this your nfs server is all set and you should be ready to connect.

No comments:

Post a Comment