Tuesday, January 13, 2009

Exporting the shared file systems

After you have added entries to your /etc/exports file, you can actually export the directories listed using the exportfs command. If you reboot your computer, the exportfs command is run automatically to export your directories. However, if you want to export them immediately, you can do so by running exportfs from the command line (as root). Here’s an example of the exportfs command:
# /usr/sbin/exportfs −a −v
exporting :/pub
exporting :/home
The −a option indicates that all directories listed in /etc/exports should be exported. The −v option says to print verbose output. In this example, the /pub and /home directories from the local server are now immediately available for mounting by client computers.

Configuring the /etc/exports file

As root user, you can use any text editor to configure the /etc/exports file to indicate what directories to share.
Here is an example of an /etc/exports file, including some entries that it could include:
/cal *.ourdomain.com(rw) # Company events
/pub (ro,insecure,all_squash) # Public dir
/home maple(rw,squash uids=0−99) spruce(rw,squash uids=0−99)

Here is what the entries in the /etc/exports file mean:
· /cal — Represents a directory that contains information about events related to the company. It is made accessible to everyone with accounts to any computers in the company’s domain (*.ourdomain.com). Users can write files to the directory as well as read them (indicated by the rw option). The comment (# Company events) simply serves as a reminder of what the directory contains.
· /pub — Represents a public directory. It allows any computer and user to read files from the directory (indicated by the ro option), but not to write files. The insecure option lets any computer, even those that don’t use a secure NFS port, to have access to the directory. The all_squash option causes all users (UIDs) and groups (GIDs) to be mapped to the anonymous user, giving them minimal permission to files and directories.
·/home — This is where you enable a set of users to have the same /home directory on different computers. Say, for example, that you are sharing /home from a computer named oak. The computers named maple and spruce could each mount that directory on their own /home directory. If you gave all users the same user name/UIDs on all machines, you could have the same /home/user directory available for each user, regardless of which computer they logged in to. The uids=0–99 is used to exclude any administrative login from another computer from changing any files in the shared directory.

Configuring the /etc/exports file

As root user, you can use any text editor to configure the /etc/exports file to indicate what directories to share.
Here is an example of an /etc/exports file, including some entries that it could include:
/cal *.ourdomain.com(rw) # Company events
/pub (ro,insecure,all_squash) # Public dir
/home maple(rw,squash uids=0−99) spruce(rw,squash uids=0−99)

Here is what the entries in the /etc/exports file mean:
· /cal — Represents a directory that contains information about events related to the company. It is made accessible to everyone with accounts to any computers in the company’s domain (*.ourdomain.com). Users can write files to the directory as well as read them (indicated by the rw option). The comment (# Company events) simply serves as a reminder of what the directory contains.
· /pub — Represents a public directory. It allows any computer and user to read files from the directory (indicated by the ro option), but not to write files. The insecure option lets any computer, even those that don’t use a secure NFS port, to have access to the directory. The all_squash option causes all users (UIDs) and groups (GIDs) to be mapped to the anonymous user, giving them minimal permission to files and directories.
·/home — This is where you enable a set of users to have the same /home directory on different computers. Say, for example, that you are sharing /home from a computer named oak. The computers named maple and spruce could each mount that directory on their own /home directory. If you gave all users the same user name/UIDs on all machines, you could have the same /home/user directory available for each user, regardless of which computer they logged in to. The uids=0–99 is used to exclude any administrative login from another computer from changing any files in the shared directory.

Sharing NFS file systems

To share an NFS file system from your Red Hat Linux system, you need to export it. Exporting is done in Red Hat Linux by adding entries into the /etc/exports file. Each entry identifies the directory in your local file system that you want to share. The entry identifies the other computers that can share the resource (or opens it to all computers) and includes other options that reflect permissions associated with the directory.
Remember that when you share a directory, you are sharing all files and subdirectories below that directory as well (by default). So, you need to be sure that you want to share everything in that directory structure. There are still ways to restrict access within that directory structure.

Setting Up an NFS File Server in Red Hat Linux

Instead of representing storage devices as drive letters (A, B, C, and so on), as they are in Microsoft operating systems, Red Hat Linux connects file systems from multiple hard disks, floppy disks, CD−ROMs, and other local devices invisibly to form a single Linux file system. The Network File System (NFS) facility lets you extend your Red Hat Linux file system in the same way, to connect file systems on other computers to your local directory structure as well.
Creating an NFS file server is an easy way to share large amounts of data among the users and computers in an organization. An administrator of a Red Hat Linux system that is configured to share its file systems using NFS has several things to do to get NFS working:
1. Set up the network — If a LAN or other network connection is already connecting the computer on which you want to use NFS (using TCP/IP as the network transport), you already have the network you need.
2. On the server, choose what to share — Decide which file systems on your Linux NFS server you want to be available to other computers. You can choose any point in the file system to make all files and directories below that point accessible to other computers.
3. On the server, set up security — There are several different security features that you can use to suit the level of security with which you are comfortable. Mount−level security lets you restrict the computers that can mount a resource and, for those allowed to mount it, lets you specify whether it can be mounted read/write or read−only. With user−level security, you map users from the client systems to users on the NFS server. In this way, users can rely on standard Linux read/write/execute permissions, file ownership, and group permissions to access and protect files.
4. On the client, mount the file system — Each client computer that is allowed access to the server’s NFS shared file system can mount it anywhere the client chooses. For example, you may mount a file system from a computer called maple on the /mnt/maple directory in your local file system. After it is mounted, you can view the contents of that directory by typing ls /mnt/maple. Then you can use the cd command below the /mnt/maple mount point to see the files and directories it contains.
Although it is often used as a file server (or other type of server), Red Hat Linux is a general−purpose operating system. So, any Red Hat Linux system can share file systems (export) as a server or use other computer’s file systems (mount) as a client. Contrast this with dedicated file servers, such as NetWare, which can only share files with client computers (such as Windows workstations) and will never act as a client.
A file system is usually a structure of files and directories that exists on a single device (such as a hard disk partition or CD−ROM). When I talk about the Linux file system, however, I am referring to the entire directory structure (which may include file systems from several disks or NFS resources), beginning from root (/) on a single computer. A shared directory in NFS may represent all or part of a computer's file system, which can be attached (from the shared directory down the directory tree) to another computer's file system.