NFS - Network File System
To install and configure NFS (Network File System) on Ubuntu securely, you need to ensure that the NFS server and client are properly set up, access is limited to trusted IP addresses, and encryption/authentication measures are in place. Here are the steps to install and configure NFS securely on an Ubuntu server:
Step 1: Install NFS Server and Client
Install the NFS server on your Ubuntu server:
Install the NFS client on the client machine (if you need to mount the NFS share):
Step 2: Create the Directory to Share
Create the directory you want to share via NFS:
Note: Adjust permissions (
777
) as per your requirements. You may choose more restrictive permissions for security purposes.
Step 3: Configure /etc/exports
File
/etc/exports
FileEdit the
/etc/exports
file to define what directories will be shared and who has access:Add an entry for the shared directory: Example:
Explanation of options:
192.168.1.0/24
: Specifies the IP range (replace with the appropriate IP address or subnet).rw
: Allows read-write access.sync
: Forces changes to be written to disk before a response is sent.no_subtree_check
: Improves performance by skipping subtree checking.no_root_squash
: This option can be risky as it allows root on the client to have root access on the server (useroot_squash
instead for more security).
For better security, you can restrict access only to specific IP addresses or subnets.
Step 4: Apply Changes
Export the shared directories:
Restart the NFS server:
Step 5: Secure NFS with Firewall Rules
Allow NFS ports in the firewall (assuming you're using UFW):
Replace
192.168.1.0/24
with your trusted subnet.Check the firewall status to ensure proper configuration:
Step 6: Mount the NFS Share on the Client
Create a mount point on the client machine:
Mount the NFS share:
Replace
192.168.1.100
with the IP address of your NFS server.To mount the NFS share automatically on boot, add the following line to
/etc/fstab
:
Step 7: Verify the Setup
Check NFS export status on the server:
Check the mounted NFS share on the client:
Test reading/writing to the NFS share: On the client, try creating a file in the NFS mount directory:
Last updated