NFS (short for Network File System) is an application-level protocol, according to the OSI model, used for distributed file systems in a local area network environment. It allows different systems connected to the same network to access remote files as if they were local. NFS was initially developed by Sun Microsystems back in 1984, with the goal of being independent of the machine, operating system, and transport protocol.
You'll typically find this protocol in UNIX systems and most GNU/Linux distributions. NFS consists of a server and one or more clients. The clients remotely access the data stored on the server. Since the data is centralized on the server, clients use less disk space.
To make this explanation easier, we'll demonstrate it with two servers on Clouding. The first one, which will be the NFS server, we'll call S1 and it will have the private IP 10.20.10.4. The server acting as the client, which will mount the folder from S1, will be called S2 and will have the IP 10.20.10.5.
Firewall Ports
The NFS protocol uses ports 2049 and 111. Make sure both ports are open for both TCP and UDP traffic on your NFS server. You can find more information on how to add a firewall rule to your server in this article.
Installing on Server S1
On S1, the first thing we’ll do is install the NFS server:
# apt update && apt install nfs-kernel-server
And we’ll create the directory to share:
# mkdir -p /home/shared
# chmod 755 /home/shared
Next, we'll restrict the user and group for security purposes:
# chown -R nobody:nogroup /home/shared
Optionally, assign write permissions if you want to be able to create files/directories:
# chmod -R a+wrx /home/shared
Now edit the configuration file /etc/exports:
# nano /etc/exports
Add the following line:
/home/shared 10.20.10.0/24(rw,subtree_check,secure,no_root_squash)
The format of the /etc/exports file is as follows:
<export> <host1>(<options>) <hostN>(<options>)...
Here, <export> refers to the directory to export, and <host1>..<hostN> refers to the host or network that will have access to the exported folder. You can specify multiple hosts or networks separated by spaces, each with its corresponding options.
The options can vary. In the example, r stands for read, and w stands for write. Subtree_check means that, besides sharing the /home/shared directory, the subdirectories within the shared folder will also be accessible. For example, if there's a folder named S1 inside /home/shared, it will also be shared.
We restart the service:
# /etc/init.d/nfs-kernel-server restart
And continue with the client setup…
Client Configuration on S2
On S2, we simply need to mount the folder using the mount command:
# apt install nfs-common # mount -t nfs 10.20.10.4:/home/shared /mnt
Another option is to mount it automatically using /etc/fstab. Edit the file:
# nano /etc/fstab
And add the mount line:
10.20.10.4:/home/shared /mnt nfs defaults 0 0
Client Configuration on Windows
First, you’ll need to install the NFS client. In Turn Windows features on or off, select Services for NFS, then choose Client for NFS and click OK:
Once installed, open a Command Prompt as an administrator and execute the following command to mount a network drive from the NFS-shared directory on the file server:
# mount -o anon \\10.20.10.4\home\shared Z:
You should see the following message:
Z: is now successfully connected to \\10.20.10.4\home\shared
The command completed successfully.
You can also verify the mount by running the mount command:
Local Remote Properties
-------------------------------------------------------------------------------
Z: \\10.20.10.4\home\shared UID=0, GID=0
rsize=1048576, wsize=1048576
mount=soft, timeout=1.6
retry=1, locking=yes
fileaccess=755, lang=ANSI
casesensitive=no
sec=sys
We hope this tutorial has helped you 🙂. Remember, if you have any questions about this or any other topic related to your servers on Clouding, feel free to reach out to us at soporte@clouding.io. We are here to help you with anything you need!