There are three common ways to distribute files between Unix (and other) systems, namely ftp, samba and nfs.
Having already covered FTP and SAMBA in previous articles, it's time to take a look at how NFS funtions under FreeBSD.
Networked file systems are common in most of the popular network operating systems and under Unix, NFS works in a very similar way to mapping drives to samba shares, but is easier to set up and a bit less 'messy'.
The plan is to allow access to one or more server directories, from one or more client Unix systems. First decision is which directory to open up and to whom.
But firstly, some background..
Using NFS, users and programs can access files on remote systems as if they were local files. NFS is composed of two sides, a client side and a server side. A system can be both a server and a client at the same time.
On the server, the NFS settings are configured using a file called /etc/exports using the following server daemons..
nfsd - the NFS daemon which services requests from NFS clients
mountd - the NFS Mount Daemon which actually carries out the requests from nfsd
The client side only needs to run a single daemon..
nfsiod - the NFS async I/O (input/output) daemon, which services requests from its NFS server.
On this occasion I am going to share the /usr/ports/distfiles directory on the server. This is where ports which are downloaded from the internet are stored by default. Methinks it might save other systems having to download them again separately.
Installation and Configuration
Forget the sysinstall
method, here's a quicker way.
a) On the server
(192.168.0.100), add the following two lines to rc.conf
nfs_server_flags="-u -t -n 4"
..followed by the directory to be shared and the client IP it should be shared with..
Reboot the server.
b) On the client
(192.168.0.14), add the following two lines to rc.conf
Reboot the client. It's fine to use all four lines if dual client/server roles are required. Make sure /etc/exports
is configured and the directories it points to exist, before starting the server service.
c) To mount the server's shared directory from the client, create a directory on the client which the server will be mounted to and then run the mount
command on the client..
mount 192.168.0.100:/usr/ports/distfiles /mnt/distfiles
- 192.168.0.100 is the IP Address of the NFS Server,
- /usr/ports/distfiles is the shared directory on the NFS server, and
- /mnt/distfiles is the directory on the client that the server's shared directory will be mapped to
Finally a cd /mnt/distfiles
on the client should allow you to browse the mounted files just as if they existed on the client itself. And yes, they're mounted as read-only