Tabla de Contenidos
Configuración de NFS
Esta es una guía rápida para configurar NFS en Slackware para usar en una LAN doméstica. El ejemplo utilizado es para la conexión de una computadora portátil con una computadora de escritorio que también tiene una partición NTFS montada en / music. Se supone que se ha establecido la conectividad de red básica. Esta guía está en gran parte cortada y pegada de otros documentos más definitivos.
De http://nfs.sourceforge.net/nfs-howto/
2.1. What is NFS? The Network File System (NFS) was developed to allow machines to mount a disk partition on a remote machine as if it were a local disk. It allows for fast, seamless sharing of files across a network. It also gives the potential for unwanted people to access your hard drive over the network (and thereby possibly read your email and delete all your files as well as break into your system) if you set it up incorrectly.
La configuración de un NFS seguro requiere un trabajo adicional, pero como los buenos hábitos de seguridad comienzan en casa, estos pasos también se presentarán.
Para los propósitos de este ejemplo:
- la computadora de escritorio se llamará DESKTOP y tiene una dirección IP 10.1.1.2
- la computadora portátil se llamará LAPTOP y tiene una dirección IP 10.1.1.3 utilizando una conexión por cable
- o la computadora portátil se llamará LAPTOP-W y tiene una dirección IP 10.1.1.4 mediante una conexión inalámbrica
Ambas computadoras se configurarán para que actúen como servidores NFS y clientes.
Configuración de acceso
/etc/hosts
En la computadora de escritorio /etc hosts debe tener líneas como
10.1.1.3 LAPTOP.<your domain> LAPTOP 10.1.1.4 LAPTOP-W.<your domain> LAPTOP-W
En la computadora portátil /etc/hosts debe tener una línea como
10.1.1.2 DESKTOP.<your domain> DESKTOP
/etc/hosts.deny
En ambas máquinas agregue
portmap:ALL lockd:ALL mountd:ALL rquotad:ALL statd:ALL
/etc/hosts.allow
En la computadora de escritorio agregar
# For NFS mount from LAN portmap: 10.1.1.3 , 10.1.1.4 lockd: 10.1.1.3 , 10.1.1.4 rquotd: 10.1.1.3 , 10.1.1.4 mountd: 10.1.1.3 , 10.1.1.4 statd: 10.1.1.3 , 10.1.1.4
En la computadora portátil agregar
# For NFS mount from LAN portmap: 10.1.1.2 lockd: 10.1.1.2 rquotd: 10.1.1.2 mountd: 10.1.1.2 statd: 10.1.1.2
La sintaxis en los ejemplos anteriores se puede alterar, p. Ej. 10.1.1. podría utilizarse para permitir el acceso desde cualquier máquina en la red 10.1.1.0/24
/etc/exports
En la computadora de escritorio agregar
# Allow export of root file system to LAPTOP with read/write and root access / LAPTOP(rw,no_root_squash,no_subtree_check) \ LAPTOP-W(rw,no_root_squash,no_subtree_check) /music LAPTOP(rw,no_root_squash,no_subtree_check,nohide) \ LAPTOP-W(rw,no_root_squash,no_subtree_check,nohide)
En la computadora portátil agregar
# Allow export of root file system to DESKTOP with read/write and root access / DESKTOP(rw,no_root_squash,no_subtree_check)
Comentarios:
- La opción no_root_squash es muy permisiva. La opción root_squash es mucho más segura.
- Permitir el acceso a todo el sistema de archivos raíz es muy permisivo. La restricción a un subdirectorio es mucho más segura.
- Se requiere la opción Nohide para mostrar el contenido de otras particiones montadas.
Daemon startup
/etc/rc.d/rc.nfsd Compruebe que este archivo es ejecutable en ambos equipos
/etc/rc.d/rc.rpc
Compruebe que este archivo es ejecutable en ambos equipos. (No es estrictamente necesario ya que /etc/rc.d/rc.nfsd ejecutará esto, pero será importante si desea que la computadora funcione solo como cliente NFS)
Puertos de enlace
a) Versiones de Slackware hasta 14.2. Para usar NFS a través del firewall, siga esta guía citada textualmente. Gracias rworkman! De http://rlworkman.net/howtos/NFS_Firewall_HOWTO
This document is intended to give you detailed steps for making NFS bind to
user-specified ports instead of random ports assigned by the portmapper.
This makes it *much* easier to run a firewall on the NFS server, as you don't
have to kludge something to find the NFS ports at each boot to open them with
iptables.
NOTE: This was written for Slackware Linux, but the general ideas should
apply on pretty much any distribution.
First, you'll want (it's not necessary, but handy to have for later) to make
sure all of this is in /etc/services. I made sure "NFS" is in all of what I
added or modified so that I can easily remove them (or just find them) if I
need them later. Note that many of these are *local* additions - they are
not official IANA assignments.
sunrpc 111/tcp # SUN Remote Procedure Call
sunrpc 111/udp # SUN Remote Procedure Call
nfsd 2049/tcp # NFS server daemon
nfsd 2049/udp # NFS server daemon
rpc.nfs-cb 32764/tcp # RPC nfs callback
rpc.nfs-cb 32764/udp # RPC nfs callback
status 32765/udp # NFS status (listen)
status 32765/tcp # NFS status (listen)
status 32766/udp # NFS status (send)
status 32766/tcp # NFS status (send)
mountd 32767/udp # NFS mountd
mountd 32767/tcp # NFS mountd
lockd 32768/udp # NFS lock daemon/manager
lockd 32768/tcp # NFS lock daemon/manager
rquotad 32769/udp # NFS rquotad
rquotad 32769/tcp # NFS rquotad
************************************************************************
Next, you'll need to modify your /etc/rc.d/rc.nfsd script accordingly:
For other linux distributions, find the script that starts these
daemons and add the needed flags.
# **** Make the quota daemon listen on port 32769
if [ -x /usr/sbin/rpc.rquotad ]; then
echo " /usr/sbin/rpc.rquotad -p 32769"
/usr/sbin/rpc.rquotad -p 32769
fi
# **** Make the mount daemon listen on port 32767
if [ -x /usr/sbin/rpc.mountd ]; then
echo " /usr/sbin/rpc.mountd -p 32767"
/usr/sbin/rpc.mountd -p 32767
fi
Now modify the /etc/rc.d/rc.rpc script (again, for other linux distros,
find the script that starts this daemon and add the needed flags).
On older versions (less than 11.0) of Slackware, rpc.statd is started
in rc.nfsd, so look there instead.
# **** Have the portmap daemon chroot to /var/empty for increased security
# **** Make the status daemon listen on port 32765 and talk on port 32766
if [ -x /sbin/rpc.portmap -a -x /sbin/rpc.statd ]; then
if ! ps axc | grep -q rpc.portmap ; then
echo "Starting RPC portmapper: /sbin/rpc.portmap -t /var/empty"
/sbin/rpc.portmap -t /var/empty
fi
if ! ps axc | grep -q rpc.statd ; then
echo "Starting RPC NSM (Network Status Monitor): /sbin/rpc.statd -p 32765 -o 32766"
/sbin/rpc.statd -p 32765 -o 32766
fi
# **** Note that you'll have to open port 32766 on the NFS clients
Now make the lock daemon listen on port 32768 only and set the nfs callback
port to 32764.
Up to Slackware 11.0, this requires a kernel boot parameter (an append=
line in lilo.conf) - a kernel stanza will look something like this:
image = /boot/vmlinuz-ide-2.4.37.11
append = "lockd.udpport=32768 lockd.tcpport=32768"
root = /dev/hda2
label = 2.4.37.11
read-only
After 11.0, but before Slackware 13.1, this requires setting module load
options in a file in the /etc/modprobe.d/ directory - I create an aptly
named file of /etc/modprobe.d/nfs.conf file and add the following lines:
options lockd nlm_udpport=32768 nlm_tcpport=32768
options nfs callback_tcpport=32764 # This is for NFSv4
In Slackware 13.1 and later, you will instead need to place the following
in /etc/sysctl.conf:
fs.nfs.nlm_udpport=32768
fs.nfs.nlm_tcpport=32768
fs.nfs.nfs_callback_tcpport=32764
Finally, you'll need to reboot the machine since the lockd module probably
will refuse to unload. Once it's rebooted, you can test to make sure all
of the changes "took" with "rpcinfo -p" or "pmap_dump" (rpcinfo is no longer
present in Slackware 14.0 or later) -- as an example, here's a snippet of
what I see here:
stora # rpcinfo -p
program vers proto port
100000 2 tcp 111 portmapper
100000 2 udp 111 portmapper
100024 1 udp 32766 status
100024 1 tcp 32766 status
100227 3 tcp 2049
100227 3 udp 2049
100021 3 udp 32768 nlockmgr
100021 3 tcp 32768 nlockmgr
100005 3 udp 32767 mountd
100005 3 tcp 32767 mountd
Copyright 2006-2011 Robby Workman, Tuscaloosa, Alabama, USA
#include <mit.h> /* Standard MIT License */
You may mirror and/or otherwise use this file as you wish so long as you
retain attribution to the author. If you have any questions, comments, or
suggestions for improvement, you may contact me at rworkman AT slackware.com
Note: Updated 20111126 for better consistency with the Debian NFS HOWTO
(since the actual port assignments aren't important, we may as well
recommend the same thing in both places); thanks to David Allen for
the pointers and recommendation...
Note: Updated 20120820 to note pmap_dump usage instead of rpcinfo in
Slackware 14+; thanks to David Allen for the heads-up on that.
b)Versión de Slackware después de 14.2
hora es más fácil usar NFS a través del firewall, ya que las opciones para NFS se pueden configurar en /etc/default/nfs y /etc/default/rpc. Simplemente es necesario descomentar las líneas apropiadas en /etc/default/rpc.
/etc/default/rpc
# See also /etc/default/nfs # Optional arguments passed to rpcbind. See rpcbind(8) #RPCBIND_OPTS="" # # Optional arguments passed to rpc.statd. See rpc.statd(8) #RPC_STATD_OPTS="" # Optional hostname to start rpc.statd with. #RPC_STATD_HOSTNAME="darkstar" # Port rpc.statd should listen on. RPC_STATD_PORT=32766 # Outgoing port rpc.statd should use. RPC_STATD_OUTGOING_PORT=32765 # # Optional options passed to rquotad. See rquotad(8) #RPC_RQUOTAD_OPTS="" # Optional port rquotad should listen on: RPC_RQUOTAD_PORT=32769 # # TCP port rpc.lockd should listen on: LOCKD_TCP_PORT=32768 # UDP port rpc.lockd should listen on: LOCKD_UDP_PORT=32768 # # Optional arguments passed to rpc.mountd. See rpc.mountd(8) #RPC_MOUNTD_OPTS="" # Port rpc.mountd should listen on: RPC_MOUNTD_PORT=32767 #
Configuración de Firewall
/etc/rc.d/rc.firewall
Aquí hay algunas líneas de ejemplo para permitir NFS
## NFS uses TCP and UDP on ports 111, 2049, 32764-32769 # Accept TCP and UDP on port 111 from local LAN for portmap $IPTABLES -A INPUT -i $EXTIF -p tcp -s $LOCAL_LAN --dport 111 -j ACCEPT $IPTABLES -A INPUT -i $EXTIF -p udp -s $LOCAL_LAN --dport 111 -j ACCEPT # Accept TCP and UDP on port 2049 from local LAN for nfsd $IPTABLES -A INPUT -i $EXTIF -p tcp -s $LOCAL_LAN --dport 2049 -j ACCEPT $IPTABLES -A INPUT -i $EXTIF -p udp -s $LOCAL_LAN --dport 2049 -j ACCEPT # Accept TCP and UDP on port 32765 from local LAN for statd listen # (set in /etc/rc.d/rc.rpc for Slackware <= 14.2 or /etc/default/rpc for Slackware >= 14.2-current) $IPTABLES -A INPUT -i $EXTIF -p tcp -s $LOCAL_LAN --dport 32765 -j ACCEPT $IPTABLES -A INPUT -i $EXTIF -p udp -s $LOCAL_LAN --dport 32765 -j ACCEPT # Accept TCP and UDP on port 32766 from local LAN for statd send # (set in /etc/rc.d/rc.rpc for Slackware <= 14.2 or /etc/default/rpc for Slackware >= 14.2-current) $IPTABLES -A INPUT -i $EXTIF -p tcp -s $LOCAL_LAN --dport 32766 -j ACCEPT $IPTABLES -A INPUT -i $EXTIF -p udp -s $LOCAL_LAN --dport 32766 -j ACCEPT # Accept TCP and UDP on port 32767 from local LAN for mountd # (set in /etc/rc.d/rc.nfsd for Slackware <= 14.2 or /etc/default/rpc for Slackware >= 14.2-current) $IPTABLES -A INPUT -i $EXTIF -p tcp -s $LOCAL_LAN --dport 32767 -j ACCEPT $IPTABLES -A INPUT -i $EXTIF -p udp -s $LOCAL_LAN --dport 32767 -j ACCEPT # Accept TCP and UDP on port 32768 from local LAN for lockd # (set in /etc/sysctl.conf for Slackware <= 14.2 or /etc/default/rpc for Slackware >= 14.2-current) $IPTABLES -A INPUT -i $EXTIF -p tcp -s $LOCAL_LAN --dport 32768 -j ACCEPT $IPTABLES -A INPUT -i $EXTIF -p udp -s $LOCAL_LAN --dport 32768 -j ACCEPT # Accept TCP and UDP on port 32769 from local LAN for rquotad # (set in /etc/rc.d/rc.nfsd for Slackware <= 14.2 or /etc/default/rpc for Slackware >= 14.2-current) $IPTABLES -A INPUT -i $EXTIF -p tcp -s $LOCAL_LAN --dport 32769 -j ACCEPT $IPTABLES -A INPUT -i $EXTIF -p udp -s $LOCAL_LAN --dport 32769 -j ACCEPT
¡El trabajo está hecho! Todo debería estar ahora en su lugar. Después de reiniciar ambas máquinas, ahora debería ser posible:
- monte el sistema de archivos raíz en la computadora de escritorio en el directorio / mnt / tmp en la computadora portátil usando
mount DESKTOP:/ /mnt/tmp
- monte el sistema de archivos raíz en la computadora portátil en el directorio / mnt / tmp en el escritorio usando
mount LAPTOP:/ /mnt/tmp
Fuentes
- Traducido por: Victor 2019/02/14 15:58 (UTC)