$ apt install nfs-kernel-server portmap
NOTE: The portmap package is only required if you want to run an NFSv2 or NFSv3 server. If all your clients support NFSv4, you can disable NFSv2 and NFSv3 (as described in the “NFSv4 only” section below) and skip the “Portmap” section below.
$ mkdir /home/share
$ vim /etc/exports
#单台例子
/home/share 192.168.1.0/255.255.255.0(rw,no_root_squash,subtree_check)
#多台例子
/home/share 192.168.1.0/24(rw) 172.16.1.0/24(ro) 10.11.12.0/24(rw)
$ /etc/init.d/nfs-kernel-server reload
NOTE:This tells the server to serve up that path, readable/writable, with root-user-id connecting clients to use root access instead of being mapped to ‘nobody’, and to use the ‘subtree_check’ to silence a warning message. Then, reloads the server.
$ cat /proc/fs/nfsd/versions
-2 -3 +4 +4.1 +4.2
NOTE:In this case, nfs2, nfs3 are disabled. NFS 4, 4.1, and 4.2 are enabled. Any client trying to connect with NFSv2 or NFSv3 should get an error.
ro: specifies that the directory may only be mounted as read only.
rw: grants both read and write permissions on the directory.
no_root_squash: is an extremely dangerous option that allows remote “root” users the same privilege as the “root” user of the host machine.
subtree_check: specifies that, in the case of a directory is exported instead of an entire filesystem, the host should verify the location of files and directories on the host filesystem.
no_subtree_check: specifies that the host should not check the location of the files being accessed withing the host filesystem.
sync: this just ensures that the host keeps any changes uploaded to the shared directory in sync.
async:ignores synchronization checks in favor of increased speed.
$ systemctl restart nfs-kernel-server
$ apt install nfs-common
$ mount -t nfs4 192.168.1.1:/home/share /local/file
$ vim /etc/fstab
192.168.1.1:/home/share /local/file nfs4 defaults,user,exec 0 0
If you aren’t certain if the share will always be available on the client, add noauto to the list of options to prevent your system from trying to mount it automatically.
192.168.1.1:/home/share /local/file nfs4 defaults,user,exec,noauto 0 0
SEE ALSO: 1.Debian NFS Server Setup 2.Debian NFS server export table