DebianDebian Based

How To Install NFS Server on Debian 12

Install NFS Server on Debian 12

In this tutorial, we will show you how to install NFS Server on Debian 12. Network File System (NFS) is a widely used protocol for sharing files and directories between Unix-like operating systems. It allows you to seamlessly access files and folders on remote servers as if they were local.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the NFS Server on a Debian 12 (Bookworm).

Prerequisites

  • A server running one of the following operating systems: Debian 12 (Bookworm).
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for NFS Server.
  • A user account with sudo privileges to execute administrative commands.

Install NFS Server on Debian 12 Bookworm

Step 1. First, update your package list to ensure you have the latest information about available packages:

sudo apt update
sudo apt upgrade

Step 2. Installing NFS Server Packages.

Install the nfs-kernel-server package on the server that will act as the NFS server:

sudo apt install nfs-kernel-server nfs-common

During the installation, you will be prompted to confirm. Type ‘y’ and press ENTER to proceed.

Step 3. Configure NFS Exports.

Create a directory that you want to share with the NFS client:

sudo mkdir -p /mnt/nfsshare

Change the ownership of the directory:

sudo chown nobody:nogroup /mnt/nfsshare

Edit the /etc/exports file to configure the directory as an NFS share:

sudo nano /etc/exports

Add the following line, replacing client_ip with the IP address of your NFS client:

/mnt/nfsshare client_ip(rw,sync,no_subtree_check)

Export the NFS share:

sudo exportfs -a

Understanding NFS Options

The options used in the /etc/exports file is as follows:

  1. rw: Allows read and write access to the shared directory.
  2. sync: Forces NFS to write changes to the disk before replying to the client.
  3. no_subtree_check: Disables subtree checking to improve NFS performance.

Step 4. Start and Enable the NFS Server.

Ensure the NFS server service is running and enabled to start on boot:

sudo systemctl start nfs-kernel-server
sudo systemctl enable nfs-kernel-server

Verify the NFS server service status:

sudo systemctl status nfs-kernel-server

If you encounter issues starting the NFS server, check the logs for any error messages:

sudo journalctl -u nfs-kernel-server -f

Step 5. Configure NFS Client

On the NFS client machine, install the nfs-common package:

sudo apt install nfs-common

Create a mount point for the NFS share:

sudo mkdir -p /mnt/nfsshare

Mount the NFS share:

sudo mount server_ip:/mnt/nfsshare /mnt/nfsshare

Replace server_ip with the IP address of your NFS server.

If you encounter issues mounting the NFS share, check the logs for any error messages:

sudo journalctl -u nfs-common -f

Step 6. Configure Firewall Rules for NFS Server

In case a firewall is enabled on your Debian system, you must allow NFS traffic. Open the necessary ports to allow the client to connect to NFS by using the following command:

sudo ufw allow from 192.168.1.0/24 to any port nfs
sudo ufw reload

Replace 192.168.1.0/24 with the appropriate subnet for your network.

Step 7. Automount NFS Share (Optional)

To automatically mount the NFS share at boot, edit the /etc/fstab file on the NFS client:

sudo nano /etc/fstab

Add the following line:

server_ip:/mnt/nfsshare /mnt/nfsshare nfs defaults,user,exec,_netdev 0 0

Replace server_ip with the IP address of your NFS server.

Understanding NFS Client Options

The options used in the /etc/fstab file is as follows:

  1. defaults: Sets the default options for NFS mounts.
  2. user: Allows regular users to mount the NFS share.
  3. exec: Allows execution of binaries on the NFS share.
  4. _netdev: Prevents the client from attempting to mount the NFS file system until the network has been enabled.

Step 8. Testing.

Create a test file on the NFS server in the shared directory:

echo "NFS test file" | sudo tee /mnt/nfsshare/testfile.txt

On the NFS client, verify that you can see the test file:

cat /mnt/nfsshare/testfile.txt

Congratulations! You have successfully installed NFS Server. Thanks for using this tutorial to install the latest version of the NFS Server on Debian 12 Bookworm. For additional help or useful information, we recommend you check the official Debian website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button