![]() |
The Network File System, or NFS protocol, is widely used in Linux for sharing files and directories between Linux systems on the same network. Here, the shared directories are created on a file server running the NFS server component. The files are added to these folders and then shared with other Linux computers after the users are granted permission to access the folder. An NFS file share is mounted on the client machine, thus making it available similar to the folders made locally. Therefore, to set up a Network File System (NFS), both the NFS server and client need to be configured. Creating the Server1. Installing NFS UtilitiesThe NFS utilities are to be installed in both server and client machines. The packages for the NFS utility can be installed using the packet manager for the specific Linux distribution. For Debian/Ubuntu sudo apt update
sudo apt install nfs-kernel-server
Here, ‘apt update’ ensures your package list is up-to-date before installation, and ‘nfs-kernel-server’ is the package that provides the NFS server components. For RedHat/CentOS sudo yum install nfs-utils
![]() Installing NFS utilitis Here, ‘yum install’ retrieves and installs the necessary packages, and ‘nfs-utils’ is the package that includes NFS server utilities. 2. Starting the NFS serverFor Debian/Ubuntu sudo systemctl start nfs-kernel-server.service
For RedHat/CentOS sudo systemctl enable --now nfs-server
![]() Starting the NFS server
3. Discovering available NFS sharesWe can also discover all the available NFS shares using the command below. showmount -e server_IP
![]() Discovering available NFS shares 4. Creating a Shared FolderAfter installing the required packages, we need to create the folder/directory to be shared on the server machine. sudo mkdir -p /mnt/shared
ls -ld /mnt/shared
![]() Creating a Shared Folder 5. Setting Up NFS ExportsNext, we will define the directory to be shared and the clients that are to be allowed to access it. This is done by adding the client IPs in /etc/exports file as shown below. sudo nano /etc/exports
![]() Setting Up NFS Exports – making changes into /etc/exports Add the following line to share the directory with a single client: /mnt/shared client_IP(rw,sync,no_subtree_check)
Replace client_IP with the actual IP of the client machine. Save and close the document. ![]() Setting Up NFS Exports 6. Exporting the Shared DirectoryIn the next step, we need to configure the export file by exporting the shared directories to make them available to the client machines. sudo exportfs -a
![]() Exporting the Shared Directory 7. Setting Permissions to the shared directoryNow that we are done exporting the shared directory, we have to define permissions for its access. sudo chown -R <user>:<groupname> /mnt/shared
sudo chmod -R 775 /mnt/shared
ls -l /mnt
![]() Setting Permissions to the shared directory Replace <user> with username and <groupname> with the group that is to be granted access. chmod -R 775 sets permissions to allow read, write, and execute for the owner and group, and read and execute for others. 8. Permitting NFS Through FirewallIf the firewall is running, we have to enable the NFS traffic. Debian/Ubuntu sudo ufw allow from client_IP to any port nfs
CentOS/RedHat sudo firewall-cmd --permanent --add-service=nfs
sudo firewall-cmd --reload
![]() Permitting NFS Through Firewall Connecting the Client’s Computers1. Installing NFS in client systemsFor the client machines to access the shared files using NFS we need to install the NFS client on all Linux systems in the network. For Debian/Ubuntu sudo apt install nfs-common
For RedHat/CentOS sudo dnf install nfs-utils ![]() Installing NFS in client systems 2. Mounting the Shared Directory on the Client MachineOn the client machine, we need to create the mounting point and run the mounting command to access the shared directory as shown below. sudo mkdir -p /mnt/nfs_shared
sudo mount server_IP:/mnt/shared /mnt/nfs_shared
3. Making the Mount PermanentTo make the mount permanent and ensure that the shared directory mounts at boot, add the following line to the /etc/fstab file on the client machine: sudo nano /etc/fstab
![]() making mount permanent with sudo nano /etc/fstab Add the line as below: mserver_IP:/mnt/shared /mnt/nfs_shared nfs defaults 0 0
Replace server_IP with the IP of the NFS server. Save and close the document. In the above line,
![]() Making the Mount Permanent To verify the mount: sudo mount | grep -i nfs
![]() Verifying the mount ConclusionNFS provides an efficient file-sharing solution to all Linux users. In fact, it is very advantageous when disk space is limited. Following the steps above one can easily configure and share files using NFS in Linux. Files Between Linux Computers Using NFS – FAQsWhat is NFS in Linux?
How to install NFS on my Linux server?
Can we restrict access to NFS shares?
Is NFS secure for file sharing?
|
Reffered: https://www.geeksforgeeks.org
Linux Unix |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 18 |