Lampros - Weird Bricks

Simple NFS

26 November, 2013 | NFS

Hi all,


So those are my quick notes on setting up NFS on FreeBSD 9.1.

This is based on the handbook and partly on the FreeBSD Diary.

Server Side

On the server side, add the following inside /etc/rc.conf:

rpcbind_enable="YES"
nfs_server_enable="YES"
mountd_enable="YES"
mountd_flags="-r"



Now you can choose to reboot or start the services manually. If you want to start them manually start from the top:

service rpcbind start



Output should be:

Starting rpcbind.



Touch (create) the file /etc/exports so you don't get weird errors:

touch /etc/exports



Now start the NFS Daemon:

service nfsd start



Output should be:

service nfsd start
NFSv4 is disabled
Starting mountd.
Starting nfsd.


As you can see `service nfsd start` also starts up mountd with it.

Now let's create a directory that we'll use as a share - in this example we'll call it /nfs_share

Create it with:

mkdir /nfs_share



Now add it in your /etc/exports file. /etc/exports is the file where we set which directories we want to share and with whom.

In this example we need a single entry:

/nfs_share -maproot=root 192.168.2.20



The -maproot=root per the handbook:

The -maproot=root flag allows the root user on the remote system to write data on the exported file system as root. If the -maproot=root flag is not specified, the client's root user will be mapped to the server's nobody account and will be subject to the access limitations defined for user, nobody.



From my testing I found that if you don't add it you will be able to read files but not write/edit.

Finally `192.168.2.20` is simply the IP address of the host I want to be able to access that directory only.

To make the change take effect make sure to restart mountd with the command:

service mountd restart


Output should be:

Stopping mountd.
Starting mountd.



Client Side
On the client things are easier.

Start by adding the following inside your /etc/rc.conf

rpcbind_enable="YES"
nfs_client_enable="YES"



Reboot the server or start the services manually:

service rpcbind start


Output should be:

Starting rpcbind.



service nfsclient start


Output should be:

NFS access cache time=60



Now create a directory to use as mountpoint - in this case we'll mount the NFS share into /mnt/nfs_share

mkdir /mnt/nfs_share



Now attempt to mount the directory:

mount 192.168.2.19:/nfs_share /mnt/nfs_share/


The above command has no output when it's successful but you can check if it worked by taking a look at your df -h output:

df -h


In my case the output is:
[code]Filesystem Size Used Avail Capacity Mounted on /dev/ada0p2 9.2G 2.2G 6.2G 26% / devfs 1.0k 1.0k 0B 100% /dev 192.168.2.19:/nfs_share 9.2G 2.2G 6.2G 26% /mnt/nfs_share

[/code]Attempt to create a file:
touch /mnt/nfs_share/justatest.txt
The above command has no output, so instead we'll just run ls -al against the file:

ls -al /mnt/nfs_share/justatest.txt


The output should look like this:

-rw-r--r--  1 root  wheel  0 Nov 25 23:58 /mnt/nfs_share/justatest.txt



Not satisfied? Go back to the server and list the file there too:

ls -al /nfs_share/justatest.txt


You should get:

-rw-r--r--  1 root  wheel  0 Nov 25 23:58 /nfs_share/justatest.txt



...aaaand done!