NFS
NFS
Introducción
NFS (Network File System) es un protocolo que permite compartir sistemas de archivos a través de la red, de forma que un cliente puede montar un directorio remoto como si fuera local.
Es muy utilizado en entornos Linux/Unix para:
- Compartir datos entre servidores
- Centralizar almacenamiento
- Proveer directorios comunes a múltiples sistemas
- Laboratorios y entornos corporativos
NFS funciona bajo un modelo cliente-servidor y se apoya principalmente en RPC. Las versiones más habituales hoy en día son NFSv3 y NFSv4, siendo esta última más segura y eficiente.
Exportar un NFS
Lo primero para exportar un NFS es disponer de:
- Un servidor con el servicio NFS instalado
- Un directorio que se quiera compartir
- Acceso de red entre servidor y clientes
Instalación del servidor NFS
En sistemas basados en RHEL:
[root@nodo1 ~]# dnf install -y nfs-utils
Updating Subscription Management repositories.
Last metadata expiration check: 6:17:32 ago on Mon 02 Feb 2026 01:07:12 PM CET.
Dependencies resolved.
==============================================================================================================================================================
Package Architecture Version Repository Size
==============================================================================================================================================================
Installing:
nfs-utils x86_64 1:2.5.4-38.el9 rhel-9-for-x86_64-baseos-rpms 460 k
Installing dependencies:
gssproxy x86_64 0.8.4-7.el9 rhel-9-for-x86_64-baseos-rpms 114 k
libev x86_64 4.33-6.el9 rhel-9-for-x86_64-baseos-rpms 55 k
libverto-libev x86_64 0.3.2-3.el9 rhel-9-for-x86_64-baseos-rpms 15 k
rpcbind x86_64 1.2.6-7.el9 rhel-9-for-x86_64-baseos-rpms 62 k
Transaction Summary
=============================================================================================================================================================
Install 5 Packages
Total download size: 706 k
Installed size: 1.7 M
Downloading Packages:
(1/5): libverto-libev-0.3.2-3.el9.x86_64.rpm 36 kB/s | 15 kB 00:00
(2/5): libev-4.33-6.el9.x86_64.rpm 207 kB/s | 55 kB 00:00
(3/5): gssproxy-0.8.4-7.el9.x86_64.rpm 165 kB/s | 114 kB 00:00
(4/5): rpcbind-1.2.6-7.el9.x86_64.rpm 84 kB/s | 62 kB 00:00
(5/5): nfs-utils-2.5.4-38.el9.x86_64.rpm 2.5 MB/s | 460 kB 00:00
--------------------------------------------------------------------------------------------------------
Total 808 kB/s | 706 kB 00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : libev-4.33-6.el9.x86_64 1/5
Installing : libverto-libev-0.3.2-3.el9.x86_64 2/5
Installing : gssproxy-0.8.4-7.el9.x86_64 3/5
Running scriptlet: gssproxy-0.8.4-7.el9.x86_64 3/5
Running scriptlet: rpcbind-1.2.6-7.el9.x86_64 4/5
Installing : rpcbind-1.2.6-7.el9.x86_64 4/5
Running scriptlet: rpcbind-1.2.6-7.el9.x86_64 4/5
Created symlink /etc/systemd/system/multi-user.target.wants/rpcbind.service → /usr/lib/systemd/system/rpcbind.service.
Created symlink /etc/systemd/system/sockets.target.wants/rpcbind.socket → /usr/lib/systemd/system/rpcbind.socket.
Running scriptlet: nfs-utils-1:2.5.4-38.el9.x86_64 5/5
Installing : nfs-utils-1:2.5.4-38.el9.x86_64 5/5
Running scriptlet: nfs-utils-1:2.5.4-38.el9.x86_64 5/5
Verifying : libverto-libev-0.3.2-3.el9.x86_64 1/5
Verifying : rpcbind-1.2.6-7.el9.x86_64 2/5
Verifying : gssproxy-0.8.4-7.el9.x86_64 3/5
Verifying : libev-4.33-6.el9.x86_64 4/5
Verifying : nfs-utils-1:2.5.4-38.el9.x86_64 5/5
Installed products updated.
Installed:
gssproxy-0.8.4-7.el9.x86_64 libev-4.33-6.el9.x86_64 libverto-libev-0.3.2-3.el9.x86_64 nfs-utils-1:2.5.4-38.el9.x86_64 rpcbind-1.2.6-7.el9.x86_64
Complete!
[root@nodo1 ~]#
Habilitar y arrancar el servicio:
systemctl enable --now nfs-server
Crear el directorio a exportar
[root@nodo1 ~]# mkdir -p /srv/nfs/datos
[root@nodo1 ~]# chown -R nobody:nobody /srv/nfs/datos
[root@nodo1 ~]# chmod 755 /srv/nfs/datos
> Los permisos pueden ajustarse según las necesidades del entorno.
---
Configurar exports
Las exportaciones NFS se definen en el fichero `/etc/exports`.
[root@nodo1 ~]# cat /etc/exports
/srv/nfs/datos *(ro,sync,no_root_squash)
/srv/nfs/datos icecube(ro,sync,no_root_squash)
/srv/nfs/datos 192.168.1.82(rw,sync,no_root_squash)
Opciones comunes:
- **rw**: lectura y escritura
- **ro**: solo lectura
- **sync**: escrituras síncronas (más seguro)
- **no_root_squash**: el usuario root del cliente mantiene privilegios
- **root_squash**: root del cliente se mapea a nobody (más seguro)
Aplicar la configuración:
[root@nodo1 ~]# systemctl status nfs-server
○ nfs-server.service - NFS server and services
Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; disabled; preset: disabled)
Active: inactive (dead)
Docs: man:rpc.nfsd(8)
man:exportfs(8)
[root@nodo1 ~]# systemctl enable nfs-server
Created symlink /etc/systemd/system/multi-user.target.wants/nfs-server.service → /usr/lib/systemd/system/nfs-server.service.
[root@nodo1 ~]# systemctl start nfs-server
[root@nodo1 ~]# systemctl status nfs-server
● nfs-server.service - NFS server and services
Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; preset: disabled)
Drop-In: /run/systemd/generator/nfs-server.service.d
└─order-with-mounts.conf
Active: active (exited) since Mon 2026-02-02 19:27:47 CET; 19s ago
Docs: man:rpc.nfsd(8)
man:exportfs(8)
Process: 7811 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
Process: 7812 ExecStart=/usr/sbin/rpc.nfsd (code=exited, status=0/SUCCESS)
Process: 7826 ExecStart=/bin/sh -c if systemctl -q is-active gssproxy; then systemctl reload gssproxy ; fi (code=exited, status=0/SUCCESS)
Main PID: 7826 (code=exited, status=0/SUCCESS)
CPU: 31ms
Feb 02 19:27:47 nodo1 systemd[1]: Starting NFS server and services...
Feb 02 19:27:47 nodo1 systemd[1]: Finished NFS server and services.
[root@nodo1 ~]#
[root@nodo1 ~]# exportfs -ra
[root@nodo1 ~]# exportfs
/srv/nfs/datos icecube
/srv/nfs/datos 192.168.1.82
/srv/nfs/datos <world>
Comprobar exportaciones activas:
[root@nodo1 ~]# exportfs -v
/srv/nfs/datos icecube(sync,wdelay,hide,no_subtree_check,sec=sys,ro,secure,no_root_squash,no_all_squash)
/srv/nfs/datos 192.168.1.82(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)
/srv/nfs/datos <world>(sync,wdelay,hide,no_subtree_check,sec=sys,ro,secure,no_root_squash,no_all_squash)
Montar un NFS
Requisitos Previos
En el cliente es necesario tener instaladas las utilidades NFS:
[root@nodo2 ~]# rpm -qa|grep -i nfs-utils
nfs-utils-2.5.4-38.el9.x86_64
Comprobar conectividad con el servidor:
[root@nodo2 ~]# ping -c2 node1
PING node1 (192.168.1.81) 56(84) bytes of data.
64 bytes from node1 (192.168.1.81): icmp_seq=1 ttl=64 time=0.398 ms
64 bytes from node1 (192.168.1.81): icmp_seq=1 ttl=64 time=0.954 ms (DUP!)
64 bytes from node1 (192.168.1.81): icmp_seq=1 ttl=63 time=1.40 ms (DUP!)
64 bytes from node1 (192.168.1.81): icmp_seq=2 ttl=64 time=0.701 ms
--- node1 ping statistics ---
2 packets transmitted, 2 received, +2 duplicates, 0% packet loss, time 1004ms
rtt min/avg/max/mdev = 0.398/0.863/1.400/0.367 ms
Ver exportaciones disponibles:
[root@nodo2 ~]# showmount -e node1
Export list for node1:
/srv/nfs/datos (everyone)
Montaje manual
Crear el punto de montaje:
[root@nodo2 ~]# mkdir -p /mnt/nfs/datos
Montar el recurso:
[root@nodo2 ~]# mount -t nfs node1:/srv/nfs/datos /mnt/nfs/datos
Verificar:
[root@nodo2 ~]# df -hT /mnt/nfs/datos
Filesystem Type Size Used Avail Use% Mounted on
node1:/srv/nfs/datos nfs4 17G 2.5G 15G 15% /mnt/nfs/datos
Montaje persistente (fstab)
Para que el montaje persista tras reinicio, añadir en `/etc/fstab`:
servidor-nfs:/srv/nfs/datos /mnt/nfs/datos nfs defaults,_netdev 0 0
Aplicar sin reiniciar:
mount -a
Configuración de red
Asegurarse de que el firewall permite el tráfico NFS.
En el servidor:
firewall-cmd --permanent --add-service=nfs
firewall-cmd --permanent --add-service=mountd
firewall-cmd --permanent --add-service=rpc-bind
firewall-cmd --reload
Comprobar servicios abiertos:
firewall-cmd --list-all
Buenas prácticas
- Restringir exportaciones por IP o red
- Evitar `no_root_squash` salvo que sea imprescindible
- Usar NFSv4 cuando sea posible
- Monitorizar permisos y espacio en disco