Setting up an OpenBSD NFS Server - NFS stands for Network File System. It is software that is included with
every OpenBSD installation. It is a way to use a computer as a file
server. A computer on the network that shares files with any number of
other computers on the
network. It can be very handy for sharing files. I use one for my music
server, which is great. I can mount my music collection from the NFS
server to my ~/Music directory on any computer on my network. In this
tutorial I will show you everything you need to know to get an NFS
server up and running.
Let's start with the exports file. The export file will contain the information necessary for our NFS server to export folders to other computers on the network. Say, for example we want to share the directory music with any computer on the network and we want to make the folder readable and writeable. The following should be in the /etc/exports file.
/home/user/music -network=10.0.0 -mask=255.255.255.0
This tells the server to export the folder /home/user/music with read and write permissions to any other computer on the network.
Next, we want to start and enable the necessary daemons on the NFS server, which include portmap, mountd and nfsd. This will start up the NFS server and have them load automatically at boot.
# rcctl enable portmap mountd nfsd # rcctl start portmap mountd nfsd
Now that we have started up our NFS server, we can open a terminal on another computer in the network and type
# showmount -e 10.0.0.88 (or whatever your servers IP address is)
It should show something like this
Export list for 10.0.0.88: /home/user/music 10.0.0.0
Finally, we should mount the exported folder in another computers directory structure. In the example below we will mount the exported folders contents in ~/Music. If you want to mount it read only, just add -o ro.
# mount -t nfs 10.0.0.88:/home/user/music ~/Music
If you make any new changes to the export file, simply reload mountd.
# rcctl reload mountd
Another option you may or may not want to use is the option to use /etc/fstab in order to automatically mount the remote export at boot. If you choose to use this option, the example below should be added to your /etc/fstab file.
10.0.0.88:/home/user/music /home/user/Music nfs rw 0 0
If you want to mount it read only, then use the following example
10.0.0.88:/home/user/music /home/user/Music nfs ro 0 0
Once you have the fstab entry in place, if you want to mount it manually right away to try it out, just type the following
# mount -a
That's it! You now have your very own file server up and running. So rather than having to copy your music to every computer on your network or after every new install, you can simply mount the remote export folder by any other computer in the network. Saves a lot of time copying files to every computer or after every new install.