NFS Server and client configuration

NFS Server and client configuration

ยท

4 min read

After reading this post you will be understanding the high level of NFS

If you have not yet checked the previous parts of this series, please go ahead and check this ๐Ÿ‘‰ Link

What is NFS?

NFS (Network File System) is basically developed for sharing of files and folders between Linux/Unix. It allows you to mount your local file systems over a network and remote hosts to interact with them as they are mounted locally on the same system. With the help of NFS, we can set up file sharing between Unix to Linux system and Linux to Unix system.

10.png

Benefits of NFS

  • NFS allows local access to remote files.
  • It uses standard client/server architecture
  • With NFS it is not necessary that both machines run on the same OS.
  • With the help of NFS we can configure centralized storage solutions.
  • Users get their data irrespective of physical location.
  • No manual refresh needed for new files.
  • Newer version of NFS also supports acl, pseudo root mounts.
  • Can be secured with Firewalls and Kerberos.

NFS Services

  • portmap : It maps calls made from other machines to the correct RPC service (not required with NFSv4).
  • nfs: It translates remote file sharing requests into requests on the local file system.
  • rpc.mountd: This service is responsible for mounting and unmounting of file systems.

Important Files for NFS Configuration

  • /etc/exports : Its a main configuration file of NFS, all exported files and directories are defined in this file at the NFS Server end.
  • /etc/fstab : To mount a NFS directory on your system across the reboots, we need to make an entry in /etc/fstab.
  • /etc/sysconfig/nfs : Configuration file of NFS to control on which port rpc and other services are listening. Installing NFS Server and NFS Client

    NFS Server & Client Configuration

Install NFS Kernel Server in Ubuntu

sudo apt update
sudo apt install nfs-kernel-server

Create an NFS Export Directory

sudo mkdir -p /mnt/nfs_share
sudo chown -R nobody:nogroup /mnt/nfs_share/
 sudo chmod 777 /mnt/nfs_share/

Grant NFS Share Access to Client Systems

sudo vim /etc/exports

* means it will access from anywhere

/mnt/nfs_share  *(rw,sync,no_subtree_check)
  • ro: With the help of this option we can provide read only access to the shared files i.e client will only be able to read.
  • rw: This option allows the client server to both read and write access within the shared directory. sync: Sync confirms requests to the shared directory only once the changes have been committed.
  • no_subtree_check: This option prevents the subtree checking. When a shared directory is the subdirectory of a larger file system, nfs performs scans of every directory above it, in order to verify its permissions and details. Disabling the subtree check may increase the reliability of NFS, but reduce security.
  • no_root_squash: This phrase allows root to connect to the designated directory.

Export the NFS Share Directory

sudo exportfs -a
sudo systemctl restart nfs-kernel-server

Allow the port in firewall Install the NFS-Common Package

 sudo apt install nfs-common

Create an NFS Mount Point on Client

sudo mkdir -p /mnt/nfs_client

Mount command.

The same entry you can enter in etc/fstab as well for the automatic mounting

 sudo mount 192.168.100.102:/mnt/nfs_share  /mnt/nfs_client

Mount Shared Directories on NFS Client

root@Kubernet-Master:~# showmount -e 192.168.100.102
Export list for 192.168.100.102:
/mnt/nfs_share *

If it is not listing, disable the iptables or allow the ports to the firewall

# Portmap ports
iptables -A INPUT -m state --state NEW -p tcp --dport 111 -j ACCEPT
iptables -A INPUT -m state --state NEW -p udp --dport 111 -j ACCEPT
# NFS daemon ports
iptables -A INPUT -m state --state NEW -p tcp --dport 2049 -j ACCEPT
iptables -A INPUT -m state --state NEW -p udp --dport 2049 -j ACCEPT
# NFS mountd ports
iptables -A INPUT -m state --state NEW -p udp --dport 10050 -j ACCEPT
iptables -A INPUT -m state --state NEW -p tcp --dport 10050 -j ACCEPT
# NFS status ports
iptables -A INPUT -m state --state NEW -p udp --dport 10051 -j ACCEPT
iptables -A INPUT -m state --state NEW -p tcp --dport 10051 -j ACCEPT
# NFS lock manager ports
iptables -A INPUT -m state --state NEW -p udp --dport 10052 -j ACCEPT
iptables -A INPUT -m state --state NEW -p tcp --dport 10052 -j ACCEPT
# NFS rquotad ports
iptables -A INPUT -m state --state NEW -p udp --dport 10053 -j ACCEPT
iptables -A INPUT -m state --state NEW -p tcp --dport 10053 -j ACCEPT

conclusion: If you want to share the same files or folder on another Linux/Unix machine you can use NFS. throughput should depend on your network

Hope you have got an idea about NFS and how to configure the NFS server and how to map NFS client in other linux/unix servers

Happy Learning ๐Ÿ“š

Thank you!

Did you find this article valuable?

Support Cloudnloud Tech Community by becoming a sponsor. Any amount is appreciated!

ย