Share, , Google Plus, Pinterest,

Print

Posted in:

Ubuntu NFS Server – Ubuntu Server 12.04

NFS is short for Network File SystemNFS server allows you to share a filesystem from a computer on the network to other computers on the same network. NFS is a server/client oriented protocol so one computer acts as a server and other computers (clients) connect to it. We will install and configure Ubuntu NFS Server on Ubuntu Server 12.04 version. Installing and configuring Ubuntu NFS Server is easy and straight forward so you should  not have any problems with it, just follow this Ubuntu NFS Server guide.

Ubuntu NFS Server
Ubuntu NFS Server

Let’s start Ubuntu NFS Server guide!

1. Update repositories

root@foo1:~# apt-get update

2. Install required packages

root@foo1:~# apt-get install rpcbind nfs-kernel-server

3. Create NFS directory and “bind” mount desired directory

In the folllowing example we would like to share /home/geekpeeknet directory via our Ubuntu NFS Server. We will create a new directory called /nfs and in it another directory called /nfs/geekpeek. With “mount –bind” option we can remount the desired directory /home/geekpeeknet to /nfs/geekpeeknet.

root@foo1:~# mkdir -p /nfs/geekpeeknet
root@foo1:~# mount --bind /home/geekpeeknet /nfs/geekpeeknet/

4. Edit /etc/exports file

/etc/exports file is where you specify which directories you want to share, which clients you want to share it to and sharing options. You can put specific IP address of your NFS clients or whole network with mask (192.168.1.0/24). Read more about all parameters HERE.

Add the following lines to /etc/exports (change NFS client IP accordingly):

/nfs                192.168.1.214(rw,sync,no_subtree_check,no_root_squash)
/nfs/geekpeeknet    192.168.1.214(rw,sync,no_subtree_check,no_root_squash)

5. Restart Ubuntu NFS Server

root@foo1:~# /etc/init.d/nfs-kernel-server restart

6. Check exports on Ubuntu NFS Server

root@foo1:~# showmount -e
Export list for foo1:
/nfs/geekpeeknet 192.168.1.214
/nfs             192.168.1.214

7. Install required packages on NFS Client

root@foo2:~# apt-get install rpcbind nfs-common

8. Check for Ubuntu NFS Server exports from NFS Client

root@foo2:~# showmount -e 192.168.1.164
Export list for 192.168.1.164:
/nfs/geekpeeknet 192.168.1.214
/nfs             192.168.1.214

9. Mount on NFS Client

root@foo2:~# mount 192.168.1.164:/nfs/geekpeeknet /mnt/

10. Test NFS mount

We just need to make a quick test to list the contents of the NFS mount point and to create a new file so we confirm our Ubuntu NFS Server is working as expected.

root@foo2:~# df -h
Filesystem                       Size  Used Avail Use% Mounted on
/dev/sda1                        7.3G 1000M  6.0G  15% /
udev                             240M  4.0K  240M   1% /dev
tmpfs                            100M  288K   99M   1% /run
none                             5.0M     0  5.0M   0% /run/lock
none                             248M     0  248M   0% /run/shm
192.168.61.164:/nfs/geekpeeknet  7.3G 1000M  6.0G  15% /mnt

root@foo2:~# ll /mnt/
total 48
drwxr-xr-x  3 geekpeeknet geekpeeknet 4096 Mar 25 08:57 ./
drwxr-xr-x 22 root        root        4096 Jan 20 13:45 ../
-rwxr-xr-x  1 root        root        3444 Mar 25 08:57 acpid*
-rwxr-xr-x  1 root        root        4596 Mar 25 08:57 apparmor*
-rwxr-xr-x  1 root        root        3444 Mar 25 08:57 apport*
-rwxr-xr-x  1 root        root        3444 Mar 25 08:57 atd*
-rw-------  1 geekpeeknet geekpeeknet  127 Mar 13 09:22 .bash_history
-rw-r--r--  1 geekpeeknet geekpeeknet  220 Jan 20 13:58 .bash_logout
-rw-r--r--  1 geekpeeknet geekpeeknet 3486 Jan 20 13:58 .bashrc
drwx------  2 geekpeeknet geekpeeknet 4096 Jan 20 13:59 .cache/
-rw-r--r--  1 geekpeeknet geekpeeknet  675 Jan 20 13:58 .profile
root@foo2:~# touch /mnt/nfs-client-test

root@foo2:~# ll /mnt/
total 48
drwxr-xr-x  3 geekpeeknet geekpeeknet 4096 Mar 25 08:58 ./
drwxr-xr-x 22 root        root        4096 Jan 20 13:45 ../
-rwxr-xr-x  1 root        root        3444 Mar 25 08:57 acpid*
-rwxr-xr-x  1 root        root        4596 Mar 25 08:57 apparmor*
-rwxr-xr-x  1 root        root        3444 Mar 25 08:57 apport*
-rwxr-xr-x  1 root        root        3444 Mar 25 08:57 atd*
-rw-------  1 geekpeeknet geekpeeknet  127 Mar 13 09:22 .bash_history
-rw-r--r--  1 geekpeeknet geekpeeknet  220 Jan 20 13:58 .bash_logout
-rw-r--r--  1 geekpeeknet geekpeeknet 3486 Jan 20 13:58 .bashrc
drwx------  2 geekpeeknet geekpeeknet 4096 Jan 20 13:59 .cache/
-rw-r--r--  1 root        root           0 Mar 25 08:58 nfs-client-test
-rw-r--r--  1 geekpeeknet geekpeeknet  675 Jan 20 13:58 .profile

11. Mount NFS on boot

If you want to mount NFS mount point on boot you need to add the following line to your /etc/fstab file.

192.168.61.164:/nfs/geekpeeknet /mnt nfs rw,hard,intr 0 0

This is the end of Ubuntu NFS Server guide! You should be able to share your filesystems from your Ubuntu Server 12.04 via NFS now.