February 21, 2009
How to: Configure NFS Server On CentOS 5
To share files and printers between Linux and Unix computers on a network.
NFS clients are installed with CentOS 5 by default.
To Start NFS Server:
# service nfs start
To Start NFS Server when the system is booted:
# chkconfig nfs on
If NFS is not working make sure
- rpc.mounted
- nfsd
- rpc.rquotad
are running by running this command:
# rpcinfo -p
NFS Severs are very simple to configure:
- Export the directory to the client.
- Mount the directory from the NFS client.
The main configuration file is /etc/exports.
Flags:
- * means all hosts
- ro means read only permissions
- rw means read/write permissions
- insecure means allow connections on port above 1024
- sync means changes to be written to disk before a command is complete.
- no_root_squash means remote root user is allowed to access the shared directory.
Example
This example assumes that you have a network between at least two computers.
server1.example.com is the nfs client computer
server2.example.com is the nfs server computer
To setup the NFS server(server2.example.com) to share the /share directory with the host named server1.example.com with read/write permissions, do the following:
- Create the share directory in the server2.example.com server
# mkdir /share
- Copy your files which you want to share to it.
# vi /etc/exports
- Insert the following:
/share server1.example.com(rw,no_root_squash,sync)
- Export the directory with the following:
# exportfs -a
- Make sure the firewall does not block access to the NFS port by running:
# system-config-securitylevel
Allow (NFS4) as "Trusted Services"
- Set SElinux
# setsebool -P nfs_export_all_rw 1
- Flush the table by running:
# iptables -F
- Restart the nfs service
# service nfs restart
- Show mounted directories:
# showmount -e
- Go to the nfs client computer(server1.example.com) and create a mount point with the following:
# mkdir /mnt/share
- mount the nfs server(server2.example.com) by the following command
# mount -t nfs server2.example.com:/share /mnt/share
- List the files in the mounted directory
# ls /mnt/share
- If you can see your files, you are done.
- To make the mount permanent:
# vi /etc/fstab
- Add the following line:
server2.example.com:/share /mnt/share nfs soft,timeout=100 0 0RHCE Red Hat Certified Engineer Linux Study Guide (Exam RH302) (Certification Press)


