Package Requirements
The default NFS in Fedora versions 14 to 21 (at least) is NFSv4 (NFS, version 4). This article makes use of the following packages found in the Fedora Repository:
nfs-utils
The nfs-utils package provides a daemon for the kernel NFS server and related tools, which provides a much higher level of performance than the traditional Linux NFS server used by most users.nfs-utils-libs
Support libraries that are needed by the commands and daemons the nfs-utils rpmsystem-config-nfs
system-config-nfs
is a graphical user interface for creating, modifying, and deletingNFS
shares.
Installation
By default NFS
is already included in most fedora installations. To verify NFS
is installed, type the following command:
rpm -q nfs-utils
this should output something like:
nfs-utils-1.2.6-3.fc17.x86_64
If not, then install the NFS
packages by typing:
su -c 'yum install -y nfs-utils system-config-nfs'
For graphical installs, use Main Menu > Add/Remove Software. This requires the root user password to run. In the Browse tab, click on the Base System group on the left, then select the Base option on the right. Click Apply to have the software and all dependencies installed. You can customize what is installed in the Base grouping by clicking on Optional packages.
Configuring NFS
There are three main configuration files you will need to edit to set up an NFS server: /etc/exports
, /etc/hosts.allow
, and /etc/hosts.deny
. The only file used in this section of the chapter is /etc/exports
to get NFS up and running.
/etc/exports
, Main configuration file/etc/hosts.allow
, Hosts to allow access/etc/hosts.deny
, Hosts to deny access
NFS is not enabled by default on all Fedora spins. To see if NFS is activated on your system, type
ps -ef | grep nfs
If you don’t see any processes named "[nfsd]"
and "[nfsd4]"
you’ll need to activate NFS with these commands:
sudo systemctl enable rpcbind sudo systemctl enable nfs-server sudo service rpcbind start sudo service nfs-server start
By default NFS
does not share out any folders or drive volumes. To create the first share, open a shell prompt, and enter the following command to begin editing the /etc/exports
file:
su -c 'vim /etc/exports'
The vi
editor window will open to what looks like a new file. This is because the /etc/exports
file has no existing configuration settings at install. The format that will be used to share folders and drive volumes is straightforward:
directory hosts(options)
Here is a break down of the 2 lines listed:
- directory, This is the directory or volume to be shared
- hosts, This is a client computer that will have access to the share. The preferred way to list the host is by IP Address, but DNS names can be used. A group of hosts can be configured by entering an IP range such as:
/var/ftp/pub 192.168.1.0/255.255.255.0(ro) /home/public 192.168.1.0/255.255.255.0(rw)
verify
1. can use nmap command “nmap -p1-1024 localhost” to verify the port “111/tcp , service rpcbind” is open.
2. on a client computer, first of all, ping the nfs server.
3. then use command mkdir /mnt
if /mnt does not existe, then mount –t nfs IPaddress:/shared_folder /mnt
. then ls -l /mnt
To mount a NFS
share permanently during system start up, edit the /etc/fstab
file the same way as you would for a local file system. The file system type should be set to nfs
. Specify the dump and fsck order (the last two entries), in our case set to zero for demonstration purposes. Our example /etc/fstab
should look like below:
... server:/var/ftp/pub /media/nfs nfs rw 0 0
Using Automount
Another way to access remote NFS
shares is to use autofs
. The difference between using the autofs
daemon and the /etc/fstab
file is autofs
will only mount the NFS
share when a file or directory is requested on the NFS
mount point. This will also speed up boot time by not waiting for a response from the remote NFS
server.
There is a good explanation of automount, valid both for Fedora 14 and 15, in the official documentation but they just forgot to say you have to install the autofs package. To do this, in Fedora 15, go to Activities → Applications → System tools → “Add/remove software”; in the “Filters” tab, choose only “Only newest packages” and check you’ve the following filters: “Installed → No filter”, “Development → Only end user files”, “Graphical → No filter”, and “Free → Only free software” (or “No filter”). Then in the “Find” field”, type “autofs”, click on “Find”, check the package whose name begins by “autofs” (for instance “autofs-1:5.0.5-38-fc15 (x86_64)”), and eventually on “Apply”. After the download and installation are complete, you can close the “Add/Remove software window”.
You may also use the following command to install the autofs
package:
su -c 'yum install autofs'
The master configuration for autofs
is the /etc/auto.master
file. Here is an example file:
# # /misc /etc/auto.misc /net -hosts # # # +auto.master
The /misc
mount is defined in a seperate file /etc/auto.misc
. The /misc
directory is reserver for autofs
mounts. New NFS
mounts should be added to the /etc/auto.misc
file. Here is an example of the /etc/auto.misc
file:
# cd -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom
To add the NFS
share to the /etc/auto.misc
, add the following line:
nfs -ro,soft,intr server:/var/ftp/pub
Save the changes made to the /etc/auto.misc
file and start the autofs
deamon: in Fedora 15, go to Activities → Applications → Other → Services, choose “autofs” in the list, then on the “start” button. Alternatively, you can use the following command at a shell prompt:
su -c 'service autofs start'
but this won’t start the autofs daemon automatically at boot. Test the changes just made by entering the following command at a shell prompt:
ls /misc/nfs
the result should be:
f8
At this Point NFS
should be up and running, and client systems should have access to the designated directories and volumes on the NFS
server. To enable the NFS
service during system startup, enter the following command at a shell prompt:
su -c 'chkconfig --levels 345 nfs on'
This starts the nfs
service on run levels 3, 4 and 5 during start up.a