NFS Server

Network File System (NFS) is a distributed file system protocol originally developed by Sun Microsystems in 1984, allowing a user on a client computer to access files over a computer network much like local storage is accessed.

Linux can be both NFS server and NFS client. Which means that it can export file systems to other systems and mount file systems exported from the other machines.

With the help of NFS, we can set up file sharing between Unix to Linux system and Linux to Unix system.

A manual refresh is not needed because the client accesses the remote file system as if it were local. Because access is granted by IP address, username and password are not required.

However, there are security risks to consider because the NFS server knows nothing about the users on the client system.

Configuring NFS server

Step 1. Install NFS server

Use the following command to install NFS

# yum -y install nfs-utils nfs-utils-lib

Step 2. Create a directory called /nfs_share with the following command create some files.

# mkdir /nfs_share

# touch nsf{1..5}

Step 3. edit the file /etc/exports and add the following line.

# vi /etc/exports

/nfs_share *(rw,sync)

/nfs_share – The directory to be shared

* – The clients allowed to access the share. You can restrict it by IP address. For example, you could, instead of the asterisk, put

192.168.0.0/24 to restrict it to clients on the 192.168.0.0/24 network.

rw – Read and Write access

sync – Sync the disk before command completion.

Step 4. Now run the exportfs command to export the directory.

# exportrf -avr

-a : Exports or un-exports all directories

-r : Reexport all directories

-u : Unexports one or more directories

-v : Provides verbose output

Step 5. Restart the services and make it permanent.

# service nfs restart

If you want NFS to start at boot, use the following command

# chkconfig --levels 235 nfs on

Configuring the NFS Client

Step 1. You must install the nfs package on the client with this command

# yum install nfs-utils nfs-utils-lib -y

Ste 2. Start the service.

# service nfs restart
# chkconfig --levels 235 nfs on

Step 3. Once the package is installed, you can use the showmount command to view exports on an NFS server.

# showmount -e 192.168.10.90

192.168.10.90 — Server IP address

Step 4. Make a directory and mount NFS over it.

# mkdir /nfs_client1

# mount -t nfs 192.168.10.90:/nfs_share /nfs_client1

Step 5: To make it permanent mount, edit /etc/fstab and add the following line.

# vi /etc/fstab

192.168.10.90:/nfs_share /nfs_client1 nfs defaults 0 0

After it was mounted, we can able to view the contents of the exported files/directories locally.

 

Advertisements