tsites notes and tips

How to setup a NFS network between Linux machines

I'm using Xubuntu for this guide, but it should work on any Linux distro based on debian.

First, install the necessary share components:

sudo apt update
sudo apt install sshfs fuse ssh nfs-kernel-server

Next, we create a share group, so we have permissions.

sudo groupadd fuse

add local admin user to group (tom in this case). Replace my name with your username

sudo usermod -a -G fuse tom

Now we decide what folder to share over NFS. We need to edit the exports file:

sudo mousepad /etc/exports

A new window in Mousepad (text editor) should open. Leave all the other text in there, just add a new line at the end. We need to add the path of the named folder AND allow all hosts, so I'm just adding this line:

/home/tom/linuxshared 192.168.1.0/24(rw,sync,no_subtree_check)

Replace 'tom' in the example above with your username. In the example above, I'm sharing a folder called 'linuxshared'. The next part is the IP range. The '/24' makes it available to all IP addresses on this IP range.

Save changes and close the window. We now need to inform the OS that you modified these share options. Run the command below to do this:

sudo exportfs -ra

We now restart the NFS share server after making our changes:

sudo service nfs-kernel-server restart

So, that's the machine we are sharing our folder FROM ready. This is our file server, so the idea is this computer should always be on and have internet access as it should be available for other computers (clients) to connect to.

Now we need to move to a different computer. You can do these steps on multiple computers. These will be computers that connect to your shared folder. (Clients)

Run the following to make sure NFS is installed

sudo apt update
sudo apt install nfs-common libguestfs-tools

Check to see what shares are available. This IP address '192.168.1.109' should be the IP address of your server machine you set up first.

showmount -e 192.168.1.109

We can now connect to and mount the shared folder. Replace the THREE instances of 'tom' in the next code snippet with your username:

mkdir /home/tom/Shared
sudo mount 192.168.1.109:/home/tom/linuxshared /home/tom/Shared

This makes a folder called 'Shared' in your home folder, it then connects to the network IP and looks for the 'linuxshared' folder. If successfull, it then maps this shared folder onto the 'Shared' folder we have just created.

So now you can drop files into this 'Shared' folder. They will appear on the Server computer, in the folder /home/yourusername/linuxshared like so:

 

Back to Forum Listing