I have various folders shared across my network. Some of those folders are for smaller files that need to be accessed from every machine on my LAN (Local Area Network), while others tend to be used for larger files (such as videos). However, for those smaller files (such as backup copies of galleys), I use Samba because it’s flexible and easy to use. For the larger files, I often go with NFS.
Also: Need to transfer files between Linux machines? Here are 5 dependable solutions
NFS stands for Network File System and is a straightforward system for sharing folders across a network. Other than the flexibility, Samba is a bit easier to work with than NFS, which is why so many opt to go that route. But when you need to save larger files to a network share, NFS is a good route to go.
I want to show you how to set up an NFS share on your network, using Linux.
How to install NFS
What you’ll need: The only things you’ll need for this are a running instance of Linux (I’ll demonstrate on the Ubuntu-based Pop!_OS), a user with sudo privileges, and a home network.
Log into your Linux machine, open a terminal window, and prepare to run a command. If your distribution of choice is Ubuntu, that command would be:
<!–>
–> <!–>
sudo apt-get install nfs-kernel-server -y
If the machine is Fedora-based, the command would be:
sudo dnf -install libnfsidmap sssd-nfs-idmap nfs-utils -y
If the machine is Arch-based, the command is:
sudo pacman -S nfs-utils
We’ve already installed the client package on Fedora and Arch and we must do the same on Ubuntu. The command for this is:
–>
sudo apt-get install nfs-common -y
How to create an NFS share
Next, we’ll create a directory to house the files for our NFS share. You can place this wherever you like, but we’re going to add it to the root directory with the command:
<!–>
–> <!–>
sudo mkdir /share
With the shared folder created, it’s time to give it the required permissions with the command:
–>
sudo chmod -R 777 /share
How to define our new share with NFS
The next step is to define the new share. For that, you’ll need to know the IP address of the machine that will access the share. With that information in hand, let’s define the share.
Open the configuration file with the command:
<!–>
–> <!–>
sudo nano /etc/exports
In the exports file, add the following:
–>
/share ADDRESS(rw)
Where ADDRESS is the IP address of the client machine that will access the NFS share. The rw means the client will have read and write access to the share.
How to open the firewall
You’ll then need to open the firewall on your server. If the server is either an Arch or Fedora-based machine, the commands for this are:
<!–>
–>
sudo firewall-cmd --permanent --zone=public --add-service=nfs sudo firewall-cmd --reload
If the machine is based on Ubuntu, the command for opening the firewall is:
–>
sudo ufw allow from 192.168.1.0/24 to any port nfs
Start the service
You can now start the NFS service. The same command can be used on Arch, Fedora, and Ubuntu systems. That command is:
sudo systemctl --enable now nfs-server
The server should start and is now ready for connections.
How to mount the share
Unlike Samba, the share isn’t automatically visible to your network. Instead, you need to mount it from your other Linux machines. Here’s how to do that.
<!–>
Say the IP address of your NFS server is 192.168.1.176 and the share is /share. To mount that on a client machine, you’ll first need to create a folder for which to mount the share. On your client machine, issue the command:
nano mkdir ~/nfs_mount
Next, open the fstab file with the command:
sudo nano /etc/fstab
At the bottom of the file, add the following line:
192.168.1.176:/share /home/USER/nfs_mount nfs rw 0 0
Where USER is your Linux username.
Save and close the file. Verify the configuration with:
sudo mount -a
You should see no errors in the output.
Also: 5 Linux file and folder management commands you need to know
At this point, the NFS share is now accessible on your Linux machine from your ~/nfs_mount directory. Any files already in the share will be available and any file you add to ~/nfs_mount (on the client) will appear in the /share directory on the server. Because we added the mount command to /etc/fstab, the share will automatically mount, even after a reboot.