Linux 101 : Sharing files over NFS
With NFS we can mount directories from the remote NFS server so that they appear as a local partition on the NFS client.
On NFS server we write for example the below line in the /etc/exports file:
- /data : is the directory on the server that we want the clients to use.
- 184.108.40.206: the IP address of the NFS client accessing the server resources.
- rw : gives the clients read/write permissions on directory.
- sync : synchronizes changes to disk before serving data.
The default NFS values, if none are mentioned, are:
- ro : for read-only access.
- root_squash : to prevent clients from logging in as "root" on the server.
The no_root_squash enables "root" actions on the server.
To give access to a whole network of clients, we add the below lines in the /etc/exports file on the NFS server:
No space between the address 220.127.116.11 and the access rights rw,sync, otherwise access will be granted to everybody.
The next step is to run the below command on the server:
- r flag : to synchronize the file system
- a flag : means all directories.
To check our exported directories, we use the below command:
On our client, we create a mount point for the remote directory:
And we mount the exported directories on it the newly created mount point:
- 18.104.22.168 : is the server's IP address.
We unmount the NFS remote directory using the below:
To allow our share to be mounted automatically, we could add it in the client's /etc/fstab file as below:
nfs is the filesystem type.