NFS

NFS stands for Network File System, and yes this does mean that you can share files over the network.. . basically what you do with this is mount folders from a server onto a client. NFS uses IP addresses for "authentication", also it uses the servers file permissions plus UID and GIDnow enough bla blah and lets just. ..

installing the server (with debian)

for the server we will need :

  • some software: nfs-kernel-server apt-get install nfs-kernel-server
  • the following kernel modules: (they are often already included in the default kernel) NFS server support [*] Provide NFSv3 server support [*] Provide server support for the NFSv3 ACL protocol extension [*] Provide NFS server over TCP support
  • optional, support to mount NFS (this will be used by the client) NFS file system support

configuration

first step is define what needs to be shared in the file /etc/exports

/mnt/share 192.168.88.8(rw) 10.20.30.100(ro) /home/user/other 192.168.88.8(rw)

explanations :

  • share path : this is where we put the full path of the folder to share (without trailing slash).
  • the IP that is allowed to access the share
  • permissions : (ro) read only, or (rw) read write

    as i was saying in the intro, the ability to actually read or write on the nfs mounted system also depends on the permissions of the files on the server itself, the client inherits the same permission "numbers" and uses the server's UID and GID. . meaning you should be careful about what you are doing here. if a shared file is chmod 644 and UID:GID is 1001:1001 then this will be potentially read writable by the user 1001 on the client and only readable by others.

now configure hosts allow and deny

/etc/hosts.deny by default close everything :

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

/etc/hosts.allow here we can open access for those we want to :

portmap: 192.168.88.8 10.20.30.100 lockd: 192.168.88.8 10.20.30.100 mountd: 192.168.88.8 10.20.30.100 rquotad: 192.168.88.8 10.20.30.100 statd: 192.168.88.8 10.20.30.100

restarting services

very simple of course

/etc/init.d/portmap restart /etc/init.d/nfs-kernel-server restart

on the clients

having a network file server is cool but without any clients . .. might as well close shop. . :] so we shall need :

  • software nfs-common portmap: apt-get install nfs-common portmap
  • required kernel modules (these are often included in the distros base kernel) : NFS file system support [*] Provide NFSv3 client support

client configuration

now all we need to do is mount the NFS resource, for this we have a few possibilities, manual mounting, fstab or on demand with autofs (check out the article autofs)

we shall consider that :

  • NFS_SERVER is the NFS server's IP address
  • /mnt/share is the share configured on the NFS server
  • /home/user/share is the mountpoint of the NFS share on the client

now we can go through the different ways of mount all this crap, i mean network file system.. .

  1. manual method (got root ?) mount NFS_SERVER:/mnt/share /home/user/share
  2. the /etc/fstab way of life NFS_SERVER:/mnt/share /home/user/share nfs rw 0 0
  3. using autofs o/ share rw NFS_SERVER:/mnt/share

    with a few more options this can become :

    share -rsize=8192,wsize=8192,soft,timeo=14,rw NFS_SERVER:/mnt/share

NFS mount options

  • hard or soft ?

    you might notice that when the NFS server is unavailable the program using that resource will start agonizing, it will struggle for life as hard as it can, it will.. . now this is normal because, by default the NFS share is mounted with the "hard" option, this means that as long as the resource is unavailable the program will just stay there waiting, as if it stopped time, once the NFS is back online it will carry about as if nothing happened. . you could add the option "soft", this will cause the program using an NFS resource to simply crash (or something) (input/output errors) in the case of availability issues.. i generally prefer this for mounting shares with music and videos and such, however if you are using a mounting the mail spool by NFS on a wired network you just might want to stay hard (did that sound weird ?)... . basically you chose depending on what you now know.

  • rsize wsize

    this defines the block size of stuff to be exchanged between both machines, different combinations for different configurations, if you want to get serious on this goto http://tldp.org/HOWTO/NFS-HOWTO/performance.html and see what they say.. . bigger, smaller, the best performance option will depend on kernel and nic.. ..

for just plain more info

http://tldp.org/HOWTO/NFS-HOWTO/