NFS (Network File System)

NFS SERVER SIDE

sudo apt install nfs-kernel-server

make sure to start rpcbind, tho it is always enabled

systemctl enable --now rpcbind

RPCBIND

  • Remote Procedure Call

  • Connects ports between client and server

  • NFSv2 and NFSv3 require rpcbind

  • NFSv4 does not need it

  • Reduces the number of required ports

  • Hurts compatibility

touk@ubuntu:/srv/nfs$ sudo mkdir files
touk@ubuntu:/srv/nfs$ sudo chmod o+rw files
touk@ubuntu:/srv/nfs$ ls -l
total 4
drwxr-xrwx 2 root root 4096 Aug 31 06:32 files

Now, i need to tell NFS to share this folder and i’ll do that in /etc/exports

sudo vim /etc/exports

touk@ubuntu:/srv/nfs$ sudo vim /etc/exports
touk@ubuntu:/srv/nfs$ sudo exportfs -r
touk@ubuntu:/srv/nfs$ cat /etc/exports
# /etc/exports: the access control list for filesystems which may be exported
#               to NFS clients.  See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes       hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4        gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes  gss/krb5i(rw,sync,no_subtree_check)
#
/srv/nfs/files  *(sync,no_subtree_check) # File added for sharing to other linux machines

Reload the config file sudo exportfs -r

sudo exportfs -v #to verify

touk@ubuntu:/srv/nfs$ sudo exportfs -v
/srv/nfs/files  <world>(ro,wdelay,root_squash,no_subtree_check,sec=sys,ro,secure,root_squash,no_all_squash)

Update portmap sudo systemctl restart nfs-kernel-server

NFS CLIENT SIDE

sudo apt install nfs-common

or in credhat distros: sudo yum install nfs-utils

df -h


Filesystem           Size  Used Avail Use% Mounted on
devtmpfs             4.0M     0  4.0M   0% /dev
tmpfs                1.8G     0  1.8G   0% /dev/shm
tmpfs                727M  9.7M  718M   2% /run
/dev/mapper/cs-root   28G  9.5G   17G  37% /
/dev/sda2            974M  463M  444M  52% /boot
tmpfs                364M   52K  364M   1% /run/user/42
tmpfs                364M   36K  364M   1% /run/user/1000

sudo mount -t nfs 192.168.1.12:/srv/nfs/files /mnt/nfs_share df -h


Filesystem                   Size  Used Avail Use% Mounted on
devtmpfs                     4.0M     0  4.0M   0% /dev
tmpfs                        1.8G     0  1.8G   0% /dev/shm
tmpfs                        727M  9.7M  718M   2% /run
/dev/mapper/cs-root           28G  9.5G   17G  37% /
/dev/sda2                    974M  463M  444M  52% /boot
tmpfs                        364M   52K  364M   1% /run/user/42
tmpfs                        364M   36K  364M   1% /run/user/1000
192.168.1.12:/srv/nfs/files   39G   34G  2.7G  93% /mnt/nfs_share

To see the NFS Activity use this command:

nfsstat

Last updated