nfs is to GNU-Linux what smb is to Windows: sharing dirs & files

“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.” (src)

NFS does not ask for passwords, instead on the server in /etc/exports is defined what client (identified by ip-address) may access what folder.

this means: nfs is only for trusted (lan) networks.

it might be okay to be used ssh tunneled but it shall not be used or active in untrusted environments.

so pros:

+ simplicity

+ speed

cons:

– security

setup the nfs-server:

hostnamectl; # tested on (server)
  Operating System: Debian GNU/Linux 11 (bullseye)
            Kernel: Linux 5.10.0-8-amd64
      Architecture: x86-64

su - root;
apt update;
apt install nfs-kernel-server;

# config the shares

vim /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)
#

# comment what this share is about (and who are the clients that want access?)
/path/on/server/to/folder/to/share1	192.168.122.72/0 *(rw,sync,no_subtree_check)

# comment what this share is about (and who are the clients that want access?)
/another/path/on/server/to/share2	192.168.122.247/0 *(rw,sync,no_subtree_check)


# activate the shares
exportfs -ra; # exportfs.man.txt
systemctl restart nfs-kernel-server;

setup the nfs-client:

hostnamectl; # tested on (server)
  Operating System: Debian GNU/Linux 11 (bullseye)
            Kernel: Linux 5.10.0-8-amd64
      Architecture: x86-64
su - root;
apt update;
apt install nfs-common;
# mount the share
mount -v -t nfs 192.168.122.1:/path/on/server/to/folder/to/share1 /media/user/nfs-mounted-share1/

debug mode on: on server

if there are problems, it might be usefull to run this script (on server and client, while trying to mount nfs share), to see what might be the problem

https://dwaves.de/2017/06/15/linux-monitor-all-logs-in-real-time-d-follow-all-show-changes-to-log-files-under-varlog/

might be outdated…

mount on boot

to mount a NFS share on boot you need to specify it in /etc/fstab (/etc/init.d/rc.local -> script did not work for me in debian-jessie)

# tested with Debian 8
su - root; # become root
# install basic software needed to mount nfs
apt update;
apt install nfs-common;
apt-get install nfs-common; # on Debian 8 and earlier

sudo vim /etc/fstab
# add this line at the end of fstab
192.168.XXX.XXX:/DATA /mnt/DATA nfs rw,rsize=32768,wsize=32768,hard,intr,async,nodev,nosuid 0 0
# reboot system and test if it works
reboot

Client Options

These options can be specified using the

mount

command, or in the

/etc/fstab

entry:

  • rw: Read/write filesystem.
  • ro: Read-only filesystem. Remote NFS clients can’t modify the filesystem.
  • hard: Applications using files stored on an NFS will always wait if the server goes down. User cannot terminate the process unless the option intr is set.
  • soft: Applications using files stored on an NFS will wait a specified time (using the timeo option) if the server goes down, and after that, will throw an error.
  • intr: Allows user interruption of processes waiting on a NFS request.
  • timeo=<num>: For use with the soft option. Specify the timeout for an NFS request.
  • nolock: Disable file locks. Useful with older NFS servers.
  • noexec: Disable execution of binaries or scripts on an NFS share.
  • nosuid: Prevents users from gaining ownership of files on the NFS share.
  • rsize=<num>: Sets the read block data size. Defaults to 8192 on NFSv2 and NFSv3, and 32768 on NFSv4.
  • wsize=<num>: Sets the write block data size. Defaults to 8192 on NFSv2 and NFSv3, and 32768 on NFSv4.

manpages:

fstab.man.txt

what can go wrong?

mount nfs errors – mount.nfs: access denied by server while mounting (null)

if you get this error it might be because the permissions for the folder on the server need to be set to 755

like this:

# on the server
chmod 755 /path/to/shared/folder

full story:

# on the server
mkdir -p /path/to/shared/folder
chmod 755 /path/to/shared/folder

vim /etc/exports
#                        ip of client allowed to access it
/path/to/shared/folder   192.168.178.125(rw,sync,no_subtree_check)
exportfs -a;

# client
mkdir -p /mnt/nfs/folder

# try to 
#         ip of the server
mount -vv 192.168.178.75:/path/to/shared/folder /mnt/nfs/folder

how to mount nfs on older Knoppix 7.2.0

knoppix is not starting a lot of services (all have to be started manually)

in order to use NFS you will have to start rpcbind

service rpcbind start; # start rpc bind service
mkdir /mnt/qnap; # create mount point
mount 192.168.1.123:/DATA /mnt/qnap; # mount share

Links:

http://nfs.sourceforge.net/

https://datatracker.ietf.org/doc/html/rfc3530

https://www.linux-nfs.org/wiki/index.php/Main_Page

https://en.wikipedia.org/wiki/Network_File_System

https://dwaves.de/2022/03/14/gnu-linux-debian-10-how-to-access-qnap-ts-219p-nas-via-nfsv4-portmap-query-failed-rpc-program-version-mismatch-protocol-not-supported/

liked this article?

  • only together we can create a truly free world
  • plz support dwaves to keep it up & running!
  • (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
  • really really hate advertisement
  • contribute: whenever a solution was found, blog about it for others to find!
  • talk about, recommend & link to this blog and articles
  • thanks to all who contribute!
admin