Setting up NFS (Network File System) on an Ubuntu server involves a few steps. Here’s a basic guide on how to do it:
Step 1: Install NFS Server on Ubuntu Server
First, you need to install the NFS server package on your Ubuntu server:
sudo apt update
sudo apt install nfs-kernel-server
sudo apt install nfs-common
sudo systemctl start nfs-server
sudo systemctl enable nfs-server
Step 2: Create a Directory to Share
You’ll need a directory on your server that you want to share with other machines. For example, let’s create a directory called /nfs_share:
sudo mkdir /nfs_share
Step 3: Configure NFS Exports
Edit the NFS exports file to specify which directories you want to share and which machines can access them. Open the /etc/exports file in a text editor:
sudo nano /etc/exports
Add a line to specify the directory you want to share and the allowed client(s). For example, to allow access to the /nfs_share directory from a specific IP address (replace client_ip with the actual IP):
• /nfs_share: The directory you want to share.
• client_ip: Replace this with the IP address of the client machine that should have access.
• rw: Grants read and write access.
• sync: Synchronous write mode (recommended for data consistency).
• no_subtree_check: Disables subtree checking for better performance.
/nfs_share client_ip(rw,sync,no_subtree_check)
Save the file and exit the text editor.
Step 4: Export the Shared Directory
Apply the changes to the NFS configuration by running:
sudo exportfs -a
Step 5: Start and Enable NFS Services
Start the NFS server and enable it to start at boot:
sudo systemctl start nfs-kernel-server
sudo systemctl start nfs-kernel-server
Step 6: Configure Firewall Rules (if applicable)
If you have a firewall enabled, you may need to allow NFS traffic. The default NFS port is 2049. You can allow NFS traffic with:
sudo ufw allow from client_ip to any port 2049
Step 7: Test NFS Share from Client
On the client machine, you can mount the shared directory. Replace server_ip with the IP address or hostname of your Ubuntu server:
sudo mkdir /mnt/nfs_share
sudo mount -t nfs server_ip:/nfs_share /mnt/nfs_share
You should now be able to access the shared directory on the client machine at /mnt/nfs_share.
Remember that this is a basic setup. For production environments, you should consider security, user authentication, and specific access permissions carefully. Additionally, NFS should ideally be used within a trusted network or with proper network security measures in place.