How to Configure NFS (Network File System) in Debian 12 Bookworm System
Categories:
3 minute read
Introduction
Network File System (NFS) is a protocol that allows for the sharing of files and directories over a network. NFS enables multiple users to access and interact with the same files from different systems as if they were local. It is widely used in Linux environments for its ease of configuration and efficiency.
In this guide, we will walk you through the process of configuring NFS on a Debian 12 Bookworm system, covering both the server and client-side setups.
Prerequisites
Before proceeding, ensure you have the following:
- A Debian 12 Bookworm system (for both the server and client)
- Root or sudo access
- A stable network connection
Step 1: Install NFS Server
To begin, update your package list and install the NFS kernel server package:
sudo apt update && sudo apt install -y nfs-kernel-server
Once installed, verify that the service is running:
sudo systemctl status nfs-server
If the service is not running, start it using:
sudo systemctl start nfs-server
To ensure the service starts on boot, enable it:
sudo systemctl enable nfs-server
Step 2: Create and Export NFS Shared Directory
Create a directory that will be shared over NFS:
sudo mkdir -p /mnt/nfs_share
Adjust the permissions so that all users can access it:
sudo chown -R nobody:nogroup /mnt/nfs_share
sudo chmod 777 /mnt/nfs_share
Next, open the NFS export file to define the shared directory:
sudo nano /etc/exports
Add the following line to share the directory:
/mnt/nfs_share 192.168.1.0/24(rw,sync,no_subtree_check)
Replace 192.168.1.0/24
with the subnet or IP addresses of the client machines allowed to access the share.
Apply the changes by running:
sudo exportfs -ra
Verify the exports:
sudo exportfs -v
Restart the NFS server to apply the changes:
sudo systemctl restart nfs-server
Step 3: Configure Firewall
If you have UFW (Uncomplicated Firewall) enabled, allow NFS traffic:
sudo ufw allow from 192.168.1.0/24 to any port nfs
sudo ufw enable
To verify the firewall settings:
sudo ufw status
Step 4: Install NFS Client
On the client machine(s), install the required package:
sudo apt update && sudo apt install -y nfs-common
Create a mount point:
sudo mkdir -p /mnt/nfs_client
Step 5: Mount the NFS Share on the Client
To manually mount the shared directory, use:
sudo mount 192.168.1.100:/mnt/nfs_share /mnt/nfs_client
Replace 192.168.1.100
with the actual IP address of the NFS server.
Verify the mounted share:
df -h
You should see an entry similar to:
192.168.1.100:/mnt/nfs_share 50G 20G 30G 40% /mnt/nfs_client
Step 6: Automount NFS Share at Boot
To ensure the share is mounted at startup, edit the /etc/fstab
file on the client machine:
sudo nano /etc/fstab
Add the following line:
192.168.1.100:/mnt/nfs_share /mnt/nfs_client nfs defaults,_netdev 0 0
Save and exit, then test the configuration:
sudo mount -a
Step 7: Test NFS Functionality
To confirm NFS is working as expected, try creating a test file from the client:
touch /mnt/nfs_client/testfile.txt
ls -l /mnt/nfs_client/
Check the server to verify that the file appears in the shared directory:
ls -l /mnt/nfs_share/
If the file is visible, your NFS setup is working correctly.
Troubleshooting
If you encounter issues, check the following:
Ensure the NFS server is running:
sudo systemctl status nfs-server
Verify the export configurations:
sudo exportfs -v
Check firewall settings:
sudo ufw status
Confirm network connectivity:
ping 192.168.1.100
Conclusion
You have successfully configured an NFS server and client on a Debian 12 Bookworm system. This setup allows for seamless file sharing across networked machines, making it an excellent solution for distributed environments. With this foundation, you can further enhance your NFS setup by implementing user permissions, secure NFS options, and advanced performance tuning.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.