The Network File System (NFS) is a client/server application that lets a computer user view and optionally store and update files on a remote computer as though they were on the user's own computer. The NFS protocol is one of several distributed file system standards for network-attached storage (NAS).
Network File System is an internet standard protocol used by Linux. RH7 support NFSv4 version of protocol by default and falls automatically to NFSv3 and NFSv2 if that is not available. NFSv4 use TCP protocol to communicate with the server, while other older version of NFS use TCP or UDP.
NFS server export share directories and NFS client should mount an exported share to local mount point. NFS share can be mounted on number of ways.
a) Manually mount using MOUNT command
b) Automatically mount by adding entry in /etc/fstab
c) Mount an NFS share on demand through a process known as auto mounting. uniting.
Server Machine (CentOS 7)
Server:10.11.12.40
1. To install NFS Package on server:
yum install nfs-utils nfs-utils-lib
Services Required for NFS:
rpcbind : The rpcbind server converts RPC program numbers into universal addresses.
nfs-server : It enables the clients to access NFS shares.
nfs-lock / rpc-statd : NFS file locking. Implement file lock recovery when an NFS server crashes and reboots.
nfs-idmap : It translates user and group ids into names, and to translate user and group names
into ids
Configuration Files:-
/etc/exports : It is a main configuration file, controls which file systems are exported to remote hosts and specifies options.
/etc/fstab : This file is used to control what file systems including NFS directories are mounted when the system boots.
/etc/sysconfig/nfs : This file is used to control which ports the required RPC services run on.
2. Start and enable the service:
systemctl start rpcbind
systemctl start nfs-server
systemctl start nfs-lock
systemctl start nfs-idmap
systemctl enable rpcbind
systemctl enable nfs-server
systemctl enable nfs-lock
systemctl enable nfs-idmap
3. Create a director to share with client and give file permission:
mkdir -p /home/ramprasath/shared/myfiles
vim /home/ramprasath/shared/myfiles/sites
chmod 740 /home/ramprasath/shared/
Note: ls -ld /home/ramprasath/shared/-> use to list out directory permission
4. Add a entry in nfs configuration file:
vim /etc/exports
/home/ramprasath/shared/ 10.11.12.0/24(rw,sync,no_root_squash)
5. Restart nfs service and check the configuration:
exportfs -r
exportfs -a
exportfs -v
showmount -e
exportfs -v : Displays a list of shares files and export options on a server
exportfs -a : Exports all directories listed in /etc/exports
exportfs -u : Unexport one or more directories
exportfs -r : Reexport all directories after modifying /etc/exports
6. Add NFS services in firewalld:-
firewall-cmd --permanent --zone public --add-service mountd
firewall-cmd --permanent --zone public --add-service rpc-bind
firewall-cmd --permanent --zone public --add-service nfs
firewall-cmd --reload
Note: You have to add above service in firewalld only if firewalld service is running. My firewalld service is in stop status, So not necessary to add.
Client Machine (Ubuntu 16):
Client server 10.11.12.44
1. Install nfs client:
sudo apt-get update
2. Create a mount point:
sudo mkdir -p /fileshare
ls -ld /fileshare
sudo chmod 744 fileshare
ls -ld fileshare/
3. Create a temp mount point:
sudo mount 10.11.12.40:/home/ramprasath/shared /fileshare
df -H --> to view the disk space and mount points, In linux we say mount points instead of drivers.
4. To unmount:
sudo umount /fileshare
5. To create a permanent mount point:
sudo vim /etc/fstab
10.11.12.40:/home/ramprasath/shared /fileshare nfs rw,sync 0 0
mount -a
df -H
6. Try to create a file/directory:
cd /fileshare
mkdir site
ls
ConversionConversion EmoticonEmoticon