Nfs docs
Comprehensive NFS Setup Guide ππ₯οΈ
Welcome! π
In this guide, we will cover everything you need to know about Network File System (NFS) configurationβfrom setting up the server to configuring the client, troubleshooting, and more! By the end, you'll have a fully functional NFS system and be equipped to handle common issues along the way. ππΎ
π Table of Contents
- Introduction to Network File System (NFS)
- When is NFS Needed?
- How NFS Works (With Mermaid Graph)
- NFS Server Configuration
- Installing NFS Packages
- Starting the NFS Services
- Creating NFS Directory & Setting Permissions
- Editing the
/etc/exports
File - Exporting NFS Filesystems
- Adjusting Firewall Settings
- NFS Client Configuration
- Installing NFS Packages on the Client
- Starting the Client Services
- Firewall Configuration
- Mounting NFS Shares
- Verifying NFS Setup
- Unmounting NFS Filesystems
- Troubleshooting Common NFS Issues
- Complete Bash Scripts for NFS Setup
1. Introduction to Network File System (NFS) ππ‘
Network File System (NFS) is a client-server file system protocol that allows users to access files on remote systems as if they were on their local machine. It is ideal for sharing directories across multiple systems in a network, especially for projects requiring real-time collaboration.
2. When is NFS Needed? π€π§
NFS is particularly useful in scenarios like:
- Development Environments: Multiple developers working on a shared codebase.
- Centralized Data Storage: Allowing clients to access and manipulate files in one centralized location.
- Backup Solutions: Efficient backups by accessing remote filesystems.
3. How NFS Works (With Mermaid Graph) π₯οΈπ
Here's a visual representation of how NFS operates:
graph TD
Client[Client Machine]
Server[NFS Server]
SharedDir[Shared Directory]
Client -->|Request Access| Server
Server -->|Authenticate| Client
Server -->|Provide Access to| SharedDir
Client -->|Read/Write Files| SharedDir
4. NFS Server Configuration π οΈπ»
Setting up the NFS server is the first step to creating your networked file system.
Installing NFS Packages π¦
First, you need to install the NFS server package:
Starting the NFS Services π
Enable and start the NFS server:
Creating NFS Directory & Setting Permissions ππ
Create the directory that will be shared across the network and set the appropriate permissions:
sudo mkdir -p /srv/nfs/shared
sudo chown nobody:nogroup /srv/nfs/shared
sudo chmod 755 /srv/nfs/shared
Editing the /etc/exports
File βοΈ
Open the /etc/exports
file and specify the shared directory and the network that will have access:
Add the following line:
Exporting NFS Filesystems π
Export the filesystem so that the NFS server shares the directories:
Adjusting Firewall Settings π‘οΈ
Make sure your firewall is configured to allow NFS traffic:
5. NFS Client Configuration ππ₯οΈ
Once the server is up and running, the next step is to configure the clients that will access the NFS shares.
Installing NFS Packages on the Client π¦
Install the required NFS packages:
Starting the Client Services π
Enable and start the NFS client services:
Firewall Configuration π‘οΈ
Allow NFS traffic through the clientβs firewall:
Mounting NFS Shares π
Create a mount point and mount the NFS share from the server:
Replace 192.168.1.100
with the IP address of your NFS server.
6. Verifying NFS Setup β π
To check if the NFS filesystem is mounted properly, run:
Alternatively, you can use:
7. Unmounting NFS Filesystems βπ
If you need to unmount the NFS share:
8. Troubleshooting Common NFS Issues π οΈπ
Here are some common issues you might encounter with NFS, along with possible solutions:
-
Permission Denied π:
-
Verify the permissions and ownership of the shared directory.
-
Check the configuration in
/etc/exports
. -
Mount Timeout π:
-
Ensure the NFS server is running.
-
Verify network connectivity between the server and client.
-
Stale File Handles ποΈ:
-
Unmount and remount the NFS filesystem.
-
Restart the NFS services.
-
Checking Logs π:
-
Review log files for errors:
-
Firewall Issues π‘οΈ:
-
Ensure the firewall allows NFS traffic on both server and client.
-
Verifying Exports π:
-
List exported NFS shares:
-
Network Connectivity π:
- Ping the NFS server from the client to ensure they can communicate:
9. Complete Bash Scripts for NFS Setup ππ
Here are complete scripts for setting up an NFS server and client.
Server Script π₯οΈ
#!/bin/bash
# NFS Server Setup Script
# Update and install NFS server
sudo apt update
sudo apt install nfs-kernel-server -y
# Enable and start NFS service
sudo systemctl enable nfs-server
sudo systemctl start nfs-server
# Create shared directory and set permissions
sudo mkdir -p /srv/nfs/shared
sudo chown nobody:nogroup /srv/nfs/shared
sudo chmod 755 /srv/nfs/shared
# Configure exports
echo "/srv/nfs/shared 192.168.1.0/24(rw,sync,no_subtree_check)" | sudo tee -a /etc/exports
# Export filesystem
sudo exportfs -a
# Adjust firewall
sudo ufw allow from 192.168.1.0/24 to any port nfs
sudo ufw reload
Client Script π₯οΈ
#!/bin/bash
# NFS Client Setup Script
# Update and install NFS client
sudo apt update
sudo apt install nfs-common -y
# Enable and start NFS client services
sudo systemctl enable nfs-client.target
sudo systemctl start nfs-client.target
# Adjust firewall
sudo ufw allow from 192.168.1.0/24 to any port nfs
sudo ufw reload
# Create mount point and mount NFS share
sudo mkdir -p /mnt/nfs/shared
sudo mount 192.
168.1.100:/srv/nfs/shared /mnt/nfs/shared