Network File Sharing (NFS) is an established protocol used in Linux for sharing files and directories across a network. It involves setting up shared directories on a server that runs the NFS server component, allowing multiple clients to access and modify files within these directories. NFS mounts these shared directories on client machines, integrating them seamlessly with their local file system.
Environment Configuration
To begin, assign IP addresses to the NFS server and the client machine:
- NFS Server: IP address – 192.168.1.10;
- NFS Client: IP address – 192.168.1.20.
NFS Server Setup
Start by installing the NFS-utils package on both the server and the client using the yum package manager:
# yum install nfs-utils |
Ensure the NFS service starts at boot:
# systemctl start nfs-server# systemctl enable –now nfs-server |
Add NFS to the firewall rules:
# firewall-cmd –permanent –add-service=nfs |
NFS Client Setup
Install the necessary NFS packages on the client machine:
# yum install nfs-utils |
Mount the NFS share with root privileges, specifying the server’s IP address:
# mount –t nfs 192.168.1.10:/nfsshare /mnt/nfsone |
Verify the mount:
# mount | grep nfs |
For permanent mounting, edit the /etc/fstab file and add the NFS share:
192.168.1.10:/nfsshare /mnt/nfs defaults 0 0 |
Execute the mount command to apply changes:
# mount –a |
Editing the /etc/exports File
Configure the directory to be shared and set access permissions in the /etc/exports file:
# vim /etc/exports/nfsshare 192.168.0.10(rw,sync,no_root_squash) |
In this example, the “nfsshare” directory allows read-write access to the client with IP 192.168.0.10.
Configuring NFS Client Machine
After installing nfs-utils, mount the NFS share from the server. The mounted directory appears in /mnt/nfsshare on the client server. For permanent mounting, update /etc/fstab with the NFS server’s details.
Finalizing NFS Setup
With these steps, the NFS server is ready to serve files to client machines, enabling efficient file sharing and collaboration.
Comparative Table: NFS Server vs NFS Client Setup
Feature | NFS Server Setup | NFS Client Setup |
---|---|---|
Purpose | Hosts the shared directories and files | Accesses and utilizes the shared resources |
IP Address | 192.168.1.10 | 192.168.1.20 |
Installation | Requires nfs-utils package | Also requires nfs-utils package |
Service Start | Enable and start nfs-server service | Mount NFS share from the server |
Firewall Config | Add NFS service to firewall rules | No specific firewall configuration required |
File System | Shares specific directories (/nfsshare) | Mounts the shared directory (/mnt/nfsone) |
Permissions | Configures access permissions in /etc/exports | Access permissions determined by server settings |
Mounting | Shares directory for client access | Permanently mounts shared directory via fstab |
Conclusion
The setup of NFS on Linux demonstrates a powerful method for sharing files across a network, distinguishing the roles of the server and client. While the server acts as the central hub for hosting and managing shared resources, the client seamlessly integrates these resources into its local environment, ensuring efficient and streamlined access.
The NFS protocol’s flexibility and simplicity make it a vital tool for organizations seeking a reliable and scalable file sharing solution. With the ability to configure permissions and access controls, NFS also ensures a secure environment for data sharing.