NFS: 让 NFS OS X 和 Linux 手牵手

使用 NFSMac OS XLinux 能互相访问共享的网络硬盘。

下面以 OS X EI Capitan (192.168.6.235) 和 Ubuntu 12.04 (192.168.6.21) 为例。

Linux –> Mac

服务端:Mac

/etc/exports:

1
/Users/hxz/test -maproot=root:wheel -network 192.168.6.0 -mask 255.255.255.0
  • /Users/hxz/test: 要通过 NFS 共享的文件目录。
  • -maproot=root:wheel: 把 client 端的 root用户映射为 Mac OS 上的 root,client端的 root组映射为 Mac OS 上的 wheel (gid=0) 组。
  • -network 192.168.0.0: 子网网段。
  • -mask 255.255.255.0: 网络掩码。

重启 nfsd:

1
2
3
4
hxz@pc0170:~/workspace/hxzqlh.com$ sudo nfsd restart
hxz@pc0170:~/workspace/hxzqlh.com$ showmount -e
Exports list on localhost:
/Users/hxz/test 192.168.6.0

客户端:Linux

1
sudo mount -t nfs 192.168.6.235:/Users/hxz/test somewhere/on/linux

Mac –> Linux

服务端:Linux

/etc/exports:

1
/home/hxz/media_set 192.168.6.0/255.255.255.0(rw,all_squash,insecure,anonuid=1000,anongid=1000)

重启 nfs server:

1
2
3
4
hxz@pc0053:~/media_set$ sudo service nfs-kernel-server restart
hxz@pc0053:~/media_set$ showmount -e
Export list for pc0053:
/home/hxz/media_set 192.168.6.0/255.255.255.0

客户端:Mac

1
2
3
4
sudo mount -t nfs 192.168.6.21:/home/hxz/media_set /Users/hxz/media_set

或:
sudo mount_nfs -o resvport 192.168.6.21:/home/hxz/media_set /Users/hxz/media_set

可视化连接方式,在 FinderGo 菜单:

卸载 nfs 硬盘:

1
sudo umount -t nfs nfs_dir
彦祖老师 wechat