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:

  1. Export the directory to the client.
  2. 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:

  1. Create the share directory in the server2.example.com server
    # mkdir /share
  2. Copy your files which you want to share to it.
  3. # vi /etc/exports
  4. Insert the following:
    /share server1.example.com(rw,no_root_squash,sync)
  5. Export the directory with the following:
    # exportfs -a
  6. Make sure the firewall does not block access to the NFS port by running:
    # system-config-securitylevel
    Allow (NFS4) as "Trusted Services"
  7. Set SElinux
    # setsebool -P nfs_export_all_rw 1
  8. Flush the table by running:
    # iptables -F
  9. Restart the nfs service
    # service nfs restart
  10. Show mounted directories:
    #  showmount -e
  11. Go to the nfs client computer(server1.example.com) and create a mount point with the following:
    # mkdir /mnt/share
  12. mount the nfs server(server2.example.com) by the following command
    # mount -t nfs server2.example.com:/share /mnt/share
  13. List the files in the mounted directory
    # ls /mnt/share
  14. If you can see your files, you are done.
  15. To make the mount permanent:
    # vi /etc/fstab
  16. Add the following line:
server2.example.com:/share /mnt/share nfs soft,timeout=100 0 0 
RHCE Red Hat Certified Engineer Linux Study Guide (Exam RH302) (Certification Press)

Spread the word

del.icio.us Digg Furl Reddit Help

Permalink • Print

Related Entries

Made with WordPress and an easy to customize WordPress theme • Sky Gold skin by Denis de Bernardy