Configurar (bàsic i ràpid) un servidor NFS a Debian 6
Última actualització: maig de 2013
Instal·lació del servidor NFS
Instal·lem els paquets necessaris:
apt-get install nfs-kernel-server portmap nfs-common nfswatch
(nfswatch és opcional i serveix per a monitoritzar el tràfic cap al servidor NFS)
NOTA: hem de tenir en compte que la carpeta a compartir ha de pertàner a nobody:nogroup. Per
exemple si la carpeta és /disc1/NFS, farem: chown nobody:nogroup /disc1/NFS
Ara definim els recursos a compartir al fitxer /etc/exports
/exemple *(ro,sync,no_root_squash,insecure)
/disc1/NFS 192.168.1.0/24(rw,sync,insecure)
- En la primera línia de l'exemple estem compartint la carpeta /exemple a qualsevol equip de la xarxa. L'usuari root es podrà connectar degut a que hem especificat la directiva no_root_squash
- La segona línia comparteix /disc1/NFS només als equips amb IP del rang 192.168.1.x.
Alguns exemples més de la manpage de exports:
EXAMPLE
# sample /etc/exports file
/ master(rw) trusty(rw,no_root_squash)
/projects proj*.local.domain(rw)
/usr *.local.domain(ro) @trusted(rw)
/home/joe pc001(rw,all_squash,anonuid=150,anongid=100)
/pub *(ro,insecure,all_squash)
/srv/www -sync,rw server @trusted @external(ro)
/foo 2001:db8:9:e54::/64(rw) 192.0.2.0/24(rw)
/build buildhost[0-9].local.domain(rw)
The first line exports the entire filesystem to machines
master and trusty. In addition to write access, all uid
squashing is turned off for host trusty. The second and
third entry show examples for wildcard hostnames and net‐
groups (this is the entry `@trusted'). The fourth line
shows the entry for the PC/NFS client discussed above. Line
5 exports the public FTP directory to every host in the
world, executing all requests under the nobody account. The
insecure option in this entry also allows clients with NFS
implementations that don't use a reserved port for NFS.
The sixth line exports a directory read-write to the
machine 'server' as well as the `@trusted' netgroup, and
read-only to netgroup `@external', all three mounts with
the `sync' option enabled. The seventh line exports a
directory to both an IPv6 and an IPv4 subnet. The eighth
line demonstrates a character class wildcard match.
Instal·lació d'un client NFS
El primer de tot es comprovar que el kernel te suport per a nfs:
lsmod @ grep nfs
Ara instal·lem els paquets necessaris:
apt-get install nfs-common portmap
(a Fedora yum install nfs-utils portmap)
Ara podem muntar el recurs remot. El podem muntar a /etc/fstab:
192.168.1.69:/disc1/NFS /mnt/NFS_remot nfs rw,hard,intr 0 1
O bé muntar-lo manualment des de la línia de commandaments i com a root:
mount 192.168.1.69:/disc1/NFS /mnt/NFS_remot
Tenim una solució intermitja que seria executar aquest mount quan s'inicia el sistema, des del fitxer /etc/rc.local.
(a Fedora seria des del fitxer /etc/rc.d/rc.local)