HOWTO: Add NFS share in RedHat Enterprise 4

Last week I enabled our server to share a directory using NFS. This should not really have been a very complex task. But it turns out that with RHEL4, anything can be more complicated than it seems at first… at the end I also include how to get Network Installation Services (NIS) running so that you can install RHEL (or many other Linux systems) over either NFS or HTTP.

As usual, resources on the Internet are, for lack of a better word, “scattered”… so in an effort to improve that, I will post my procedure here.

I am using RedHat Linux Enterprise 4 with a Firewall enabled (which causes most of the frustration).

Following is the procedure. Please, if you use this and have any comments or suggestions, feel free to email me or post a comment (reg required) so that I can add your experience to the howto.

Here goes:

Procedure for creating NFS shares on RedHat Enterprise 4 ES with Firewall and enabling NIS (Network Install Service).

  1. Create directory for NFS export at (eg. /var/data/public). Directory structure must have read access for All or Everyone (I use 755) from / level.
  2. Edit: /etc/exports (we’ve created a read-only export that is only accessible from our local subnet)insert as follows (all on one line):
    • /var/data/public/NFS/RHEL4 192.168.1.0/255.255.255.0(ro,insecure,async)
    • You can also do this using the control panel at the GUI in System Settings.
  3. Next… we opened ports on the Firewall to allow access to NFS clients. In GUI “Security Settings” panel… open following ports in Firewall:
    • 111:tcp, 111:udp (for portmap)
    • 2049:tcp, 2049:udp (for nfsd)
    • 32767:tcp, 32767:udp (for mountd)
  4. Finally. We must modify the nfs startup script to bind mountd to a specific port. Otherwise it use a different port everytime we restart the service.
    • in /etc/init.d/nfs look for:
    • “$MOUNTD_PORT”
    • Before this line… add a new line:
    • MOUNTD_PORT=32767
  5. Now restart the nfs service with “service nfs restart”
  6. Test the service on your client.
    • If you get a “BAD MNT” error, then double check that mountd is using the correct port (rpcinfo -p).
    • If you get a “RPC connect failure”, then check that the firewall has the correct ports open.
    • If you get a “permission denied” error, check that the directory has read/execute access for “all”… and that all directories up to your NFS export also have read/execute permissions for “all”.
  7. You can now add files to the NFS share.
    • If you want NIS, simply insert Disks 1 through 4 and type (as root):
    • cp -var /path/to/cdrom/RedHat /var/data/public/NFS
    • This will copy all files and directories including base and RPMS to the NFS folder
    • Once all the files have been copied… you should be able to use /var/data/public/NFS/RedHat as your path for NIS installs.
    • You can also enable NIS over HTTP by creating a new directory or virtual host in your httpd.conf file and pointing it at your NFS directory. Make sure to enable directory listing (with a .htaccess file or in the conf)