NFS (Network File System) can be used to share files between different servers or computers on a network. It allows you to mount a remote directory on a local machine and access it as if it were a local directory. We’ll walk you through how to set up an NFS mount on Ubuntu, including port settings for your firewall.
Installing NFS server
Install the NFS server on the computer that will be hosting the shared directory:
sudo apt install nfs-kernel-server
Creating shared directory
On the computer with the NFS server, create the directory that you want to share. For example, if you want to share the directory “/var/shared”, you can create it with the following command:
sudo mkdir /var/shared
Configuring NFS server
Next, you need to configure the NFS server to share the directory you just created. Open the /etc/exports
file with a text editor:
sudo nano /etc/exports
The /etc/exports
file has comments showing the general structure of each configuration line. The syntax is as follows:
directory_to_share client(share_option1,share_option2,...)
Add the following line to the end of the file, replacing “192.168.1.0/24” with the IP address range of the clients that will be accessing the shared directory:
/var/share 192.168.1.0/24(rw,sync,no_subtree_check)
Here are some of the popular options that you can use with the above line:
rw
: Gives the client computer both read and write access to the volume.sync
: Forces NFS to write changes to disk before replying. This results in a more stable and consistent environment since the reply reflects the actual state of the remote volume. However, it also reduces the speed of file operations.no_subtree_check
: Prevents subtree checking, which is a process where the host must check whether the file is actually still available in the exported tree for every request. This can cause many problems when a file is renamed while the client has it opened. In almost all cases, it is better to disable subtree checking.no_root_squash
: By default, NFS translates requests from a root user remotely into a non-privileged user on the server. This was intended as security feature to prevent a root account on the client from using the file system of the host as root.no_root_squash
disables this behavior for certain shares.
When you’re done, save and exit the file. Then, for the changes to take effect, and to make the shares available to the clients that you configured, restart the NFS service:
sudo systemctl restart nfs-kernel-server
Next: Adjusting firewall on NFS server
Leave a Reply