Mon Oct 2 17:08:03 2017 UTC

Setup NFS server

Introduction

NFS means Network File System. It permit you to share files between machines. The only condition is, all machines NEED TO support the NFS service. Fortunately all the distributions support it.

Packages to install

To setup a NFS server it's quite simple. You need to install, configure and start it. Let's install all those packages:

On the server

get nfs-utils nfs-utils.service

On the client(s)

get nfs-utils

Configuration

They are only 2 files to configure: One on the server, one on each client:

In our example, it's the /home/tnut/documents folder we want to share:

Server configuration

We need to do it in root:

su -

We create the /etc/exports file like this:

cat  > /etc/exports << EOF
/home/tnut/documents 192.168.1.0/24(rw,no_root_squash,subtree_check,anonuid=99,anongid=99)
EOF

We want to share the /home/tnut/documents and make it accessible from all other machines having an IP adress between 192.168.1.1 et 192.168.1.254.

Configuration on the server is already done, lets move on to the client(s)

Client(s) configuration

cat >> /etc/fstab << EOF
192.168.1.20:/home/tnut/documents /home/tnut/documents nfs auto,rw,vers=3,_netdev,rsize=8192,wsize=8192 0 0
EOF

In this example, the NFS server is at the adress 192.168.1.20

Starting all the services

We need to start the service on the server by reboot it or by typing:

On the server

/etc/rc.d/init.d/rpcbind start
/etc/rc.d/init.d/netfs start
/etc/rc.d/init.d/nfs-server start

On the client(s)

/etc/rc.d/init.d/rpcbind start
/etc/rc.d/init.d/netfs start

If you prefer, you can reboot the server and client(s)

Test the service

All the services are now configured, they should be no error message when starting them.

On the server

The NFS server is a client as well so it's absolute possible to test the service on the server.

On the server, we create a "temporary" folder:

In root:

mkdir /root/bidon

And now the mounting test (still on the server):

mount -o vers=3 192.168.1.20:/home/tnut/documents /root/bidon

No errors should show up. The mount is done.

We can check it by looking it's content:

ls -l /root/bidon
....
My letters
Pictures
MP3
...
...

The NFS server setup has been successfully tested. We can unmount the folder now.

umount /root/bidon

Once umounted, the folder can be removed without any error:

rm -d /root/bidon

We can now proceed to the client tests

On a client

The test is exactly the same, this time we test the folder which will be automatically mounted when the client is started:

mount -o vers=3 192.168.1.20:/home/tnut/documents /home/tnut/documents

No errors should show up. The mount is done.

We can check it by looking it's content:

ls -l /home/tnut/documents
....
My letters
Pictures
MP3
...
...

Conclusion

Congratulations, your NFS server is now working fine.