NFS stands for "Network File System". It was developed by Sun Microsystems in 1980 to share Files and Printer between Unix or Linux systems. It allows a client to mount the local file system of server over network. By default RHEL6 use NFSv4 if the server supports it.
# yum groupinstall "NFS file server"
OR
# yum install nfs*
If you have not configured yum server then you can install from the package directory by using rpm command as:
# rpm -ivh nfs* --nodeps --force
# rpm -ivh rpcbind* --nodeps --force
# service nfs restart
# service rpcbind restart
(Note: In these commands restart is for restarting the services. It may possible that services are not started yet, So restart will not bother that services are running or not.)
Note: Some valid host entries in "/etc/exports" file
/home/user/nfs_share * (rw,sync)
/home/user/nfs_share *.example.com (rw,sync)
/home/user/nfs_share 192.168.1.10 (rw,sync)
/home/user/nfs_share 192.168.1.0/255.255.255.0 (rw,sync)
/home/user/nfs_share 192.168.1.0/24 (rw,sync)
/home/user/nfs_share @netgroup (rw,sync)
# umount /mnt/shared_files
NFS Services
NFS allows local access to remote files. It uses PORT 2049 and nfs demon. In Network File System, there are two packages required in RHEL6:
- nfs-utils
- rpcbind
Installation Of Required Packages
To install those packages run this command as root user:
# yum groupinstall "NFS file server"
OR
# yum install nfs*
If you have not configured yum server then you can install from the package directory by using rpm command as:
# rpm -ivh nfs* --nodeps --force
# rpm -ivh rpcbind* --nodeps --force
Starting the services
To start the services use these commands as root user in both server and client:# service nfs restart
# service rpcbind restart
(Note: In these commands restart is for restarting the services. It may possible that services are not started yet, So restart will not bother that services are running or not.)
Configuring the SERVER and CLIENTS
Suppose our server's ip address is 192.168.1.1 and our client's ip address is 192.168.1.2. Then here are the steps to configure the server and client for the NFS service
Server Configuration:
Suppose we want to share the directory "/home/user/nfs_share" for NFS service then follow these steps:
- "/etc/exports" is the file where we will type the share files information. Open editor with this file and add entry for the directory to be share in this format
<Path_of_Directory_To_Share> <Client's_IP_address> <Permissions>
in our example it will be:
/home/user/nfs_share 192.168.1.2 (rw,sync)
- Save this file and and check with cat command as:
# cat /etc/exports
/home/user/nfs_share 192.168.1.2 (rw,sync)
#
- Allow PORT 2049 (NFS4) from the firewall which is in menu:
"System > Administration > Firewall"
Or you can use "setup" command...
- Restart both of the service as:
# service nfs restart
# service nfs restart
- NFS Server is configured successfully.
rw | read/write permissions |
ro | Sread-only permissions |
insecure | Allows the use of ports over 1024 |
sync | Specifies that all changes must be written to disk before a command completes |
no_wdelay | Forces the writing of changes immediately |
root_squash | Prevents root users |
Note: Some valid host entries in "/etc/exports" file
/home/user/nfs_share * (rw,sync)
/home/user/nfs_share *.example.com (rw,sync)
/home/user/nfs_share 192.168.1.10 (rw,sync)
/home/user/nfs_share 192.168.1.0/255.255.255.0 (rw,sync)
/home/user/nfs_share 192.168.1.0/24 (rw,sync)
/home/user/nfs_share @netgroup (rw,sync)
Client Configuration
Server has shared "/home/user/nfs_share" directory, Now Client wants to access the directory then client should follow these simple steps:
- create a directory in /mnt folder as following command using root user:
# mkdir /mnt/shared_files - mount the nfs file system of server to this created directory as:
# mount -t nfs 192.168.1.1:/home/user/nfs_share /mnt/shared_files - goto "/mnt/shared_files" directory and perform list command. You will see all the file of server's "/home/user/nfs_share" in "/mnt/shared_files".
# ls -al /mnt/shared_files
- Client is also configured successfully.
# umount /mnt/shared_files
Testing NFS Service
If client has write permission then Just create a file in "/mnt/shared" directory from client's system and write something in it. You will see the file in Server's system. If client has read only permission then create file from server's system and try to read the file from client's system.
Important commands for NFS.
- showmount -e : Shows the available shares on your local machine
- showmount -e <server-ip or hostname>: Lists the available shares at the remote server
- showmount -d : Lists all the sub directories
- exportfs -v : Displays a list of shares files and options on a server
- exportfs -a : Exports all shares listed in /etc/exports, or given name
- exportfs -u : Unexports all shares listed in /etc/exports, or given name
- exportfs -r : Refresh the server’s list after modifying /etc/exports
No comments:
Post a Comment