How to configure NFS on Ubuntu?

To set up NFS (Network File System) on Ubuntu, you need to follow these steps:

  1. Install NFS server software package:
    Open the terminal and run the following command to install the NFS server software package:
  2. Update the system using ‘sudo apt update’ and then install the NFS kernel server with ‘sudo apt install nfs-kernel-server’.
  3. Create a shared directory:
    Create a shared directory on the NFS server, where you can choose a custom directory path. For example, create a directory named /nfs/share.
  4. Create a directory named “share” in the “nfs” directory with full read, write, and execute permissions for all users.
  5. Set up NFS sharing:
    Open and edit the /etc/exports file, and add the following content:
  6. Allow all users to read and write to the NFS share with synchronous access and no subtree checking.
  7. This will allow all clients to access the /nfs/share directory with read and write permissions.
  8. Reload NFS configuration by running the following command:
  9. Execute the command “sudo exportfs -a” and then restart the NFS kernel server using “sudo systemctl restart nfs-kernel-server”.
  10. Setting up NFS Client:
    Once the NFS server is configured, you need to set up the NFS client to access the shared directory.
  11. Install the NFS client software package:
    Open the terminal on the NFS client and run the following commands to install the NFS client software package:
    sudo apt update
    sudo apt install nfs-common
  12. Mounting NFS shared directory:
    To mount NFS shared directory, run the following command (for example, mount the shared directory to /mnt/nfs):
    sudo mkdir -p /mnt/nfs
    sudo mount :/nfs/share /mnt/nfs

    Please replace with the IP address of the NFS server.

  13. Automatically mount NFS shares:
    If you want to automatically mount NFS shared directories at system startup, you can edit the /etc/fstab file and add the following line:
    :/nfs/share /mnt/nfs nfs defaults 0 0

    After saving and closing the file, run the following command to test the automatic mounting:
    sudo mount -a

Now, you have successfully configured NFS on Ubuntu. The NFS server will share directories with NFS clients, allowing them to access and share files.

bannerAds