NFS(Network File System)是由Sun开发的用于网络上文件共享的协议.NFS使用起来很方便,所以得到了广泛的应用.但由于它的认证机制是基于IP地址的,因而容易被攻击. 
注意NFS是基于rpc机制的,所以portmap服务一定要打开. 
在RedHat中: 
/etc/rc.d/init.d/nfs 
... 
[ -f /usr/sbin/rpc.nfsd ] || exit 0 
[ -f /usr/sbin/rpc.mountd ] || exit 0 
[ -f /etc/exports ] || exit 0 
# See how we were called. 
case ""$1"" in 
start) 
# Start daemons. 
echo -n ""Starting NFS services: "" 
daemon rpc.mountd 
daemon rpc.nfsd 
echo 
touch /var/lock/subsys/nfs 
;; 
... 
可以看出由三个重要文件,rpc.mountd,rpc.nfsd,/etc/exports. 
rpc.nfsd 
用于处理客户文件系统的请求. 
rpc.mountd 
但从一个NFS客户受到一个mount请求,根据/etc/exports来决 
定是否提供服务,如果被允许,rpc.mountd创建一个文件句柄并在 
/etc/rmtab中加上一条纪录.该记录在umount时被删除. 
/etc/exports 
NFS的配置文件. 
例如: 
这里有四台机器:192.168.1.1 192.168.1.2 
192.168.1.3 192.168.1.4 
在192.168.1.1上: 
/etc/exports包含下面一条: 
/home/ftp/pub 192.168.1.0/255.255.255.0(ro) 
在192.168.1.2上: 
showmount -e 192.168.1.1 
/home/ftp/pub ro 
mount 192.168.1.1:/home/ftp/pub /mnt 
这样在192.168.1.2上就可以自由的访问192.168.1.1的 
/home/ftp/pub下的文件,仿佛它们就存在/mnt下. 
/etc/exports的配置规则: 
每一条都有下面的形式: 
directory machine_name(option) 
directory就是本地的一个目录. 
machine_name描述那些及其有权利访问该目录. 
option描述了提供了什么样的服务,或者说客户有什么样的权利. 
machine_name的格式: 
single host: 一个机器名或一个ip地址. 
/tmp friday(ro) 
/tmp 192.168.1.3(ro) 
wildcard:使用了通配符,* 或 ?. 
/tmp *.cs.foo.edu(ro) 
IP 子网: 如: 192.168.1.0/255.255.255.0 
=public: 所有机器都有权利. 
option: 
ro 只读 
rw 读写 
noaccess 无权 
link_relative/link_absolute 对符号连接的处理,前者是 
加上""./"",后者是保持不便. 
在NFS中存在一个anonymous用户用于处理用户的访问权限. 
root_squash/no_root_squash:是否将root映射到anonymous. 
squash_uid/squash_gid/all_squash: 
如何处理用户的uid和gid. 
map_static:启动静态映射. 
如: map_static=/etc/nfs/foobar.map 
/etc/nfs/foobar.map 
# remote local 
uid 0-99 - #squash 
uid 100-500 1000 
gid 0-49 - #squash 
gid 50-100 700 
一个复杂的例子: 
/ master(rw) trusty(rw,no_root_squash) 
/usr *.local.domain(ro) 
/project proj*.local.domain(rw) 
/pub =public(ro) 
/pub/private (noaccess) 
由于它的认证机制是基于IP地址的,因而容易被ip-spoofing攻击. 
一般除非必要不要打开这项服务.