Monday, December 3, 2007

/etc/fstab, /etc/mtab, /etc/exports, file systems, DNS, NFS, NIS, and the Art of Linux


y0duh says, “Linux very powerful operating system (OS), very powerful indeed.” How many times have you heard the praises of Linux being sung by the hacker community (not to be confused with crackers), hardcore geeks, computer enthusiasts, or anyone who detests Microsoft? Well this article is not meant to be one of those intended to sway the masses to convert to Linux; in fact, it is written for purely selfish reasons. In December I intend to take the Linux+ certification exam followed by the RHCT certification exam in February. At this point some of the network administration files and services, particularly those that pertain to distributing information, are still a little murky, which inspired this article. The files and services that I am referring to are the NFS, NIS, and DNS services and the /etc/mtab, /etc/fstab, and /etc/exports files.


0000. What is Linux?

Linux is an open source multi-user OS developed by Linus Torvalds in 1991 using Richard Stallman’s “GNU is Not Unix” (GNU) project. Stallman is the founder of the Free Software Foundation and the author of the Free Software Manifesto. Torvalds created Linux partially because he was bored, partially as a hobby, but mostly because Minux, the OS Torvalds was using at the time, had limited capabilities as an OS. Torvalds initially started developing Linux by writing a terminal emulation program for the Minux OS. He eventually started adding features to the terminal emulator program as was necessary. This project evolved into what eventually became the first version of the Linux OS. Torvalds then uploaded the OS to the Internet, and asked other programmers to post any recommendations and/or suggestions they had about his OS. To Torvald’s surprise, people immediately started making suggestions for the new operating system and even requested to start supporting the software. The rest, as they say, is history.

A key feature that makes Linux so powerful is the command line interface (CLI). Anything done via the graphical user interface (GUI) can be done from the command line. In fact some, like me, believe that the GUI hinders a user’s ability to utilize all of an OS’ features and abilities. It is often more difficult finding features while navigating with the GUI. From the CLI a user can do exactly what she intends to do with the OS. It is not that Windows lacks the tools of Linux; it just hinders a user by scattering many of its features throughout the OS (I can only make this point about Windows since the Mac OS X is built on the UNIX kernel). Interestingly it appears that lately even Windows is making its CLI more functional.

Today Linux is over 16 years old and has numerous distributions. Usually a Linux user learns and loyally aligns with one of these distributions (personally I prefer Red Hat or Suse). However, the easiest way to begin using Linux is to decide which distribution to use and to download a copy from one of the many websites.


0001. Linux File Systems

The Linux file system is made up of multiple directories that are arranged in a hierarchical structure. The file structure can be described as a tree with the root or “/” directory acting as the trunk. All other directories branch off the root directory. Each directory houses a particular type of file. For instance, the /etc directory contains all of the OS configuration files. If a program needs to be configured, the program’s configuration file is almost always in the /etc directory. The /home directory contains the OS user(s) files, and of course the /boot directory contains booting instructions files. The /var directory houses the OS log files. Other directories that bear mentioning are the /mnt, /src, and /tmp directories. One other directory critical to Linux is the swap file directory. The swap file acts as the virtual memory for a Linux system. It is often recommended that this file be twice the size of the amount of physical RAM of a computer. The swap file is the equivalent of the virtual memory file of a Windows machine. It is recommended that all directories be installed on separate partitions. The one exception to this practice is the /home directory. It should be noted that the only two files absolutely necessary for a Linux installation are the swap and “/” directories.

Some novice users have a difficult time switching between different Linux distributions because certain files are often placed in different locations; however, the basic directory structures are comparable between all Linux brands. In fact most Linux OS distributions have similar, although not exact, file structures.


0010. Network File System (NFS)

NFS allows files to be shared across a Linux network. Case in point, individual files and directories can be shared among multiple users on a network. Often one computer acts as a server while other client computers access it for particular files or directories. Setting up NFS is fairly straight forward; the configuration file is naturally located in the /etc directory. This file, /etc/exports, is used to configure NFS by indicating which files/directories are shared remotely. The format for the /etc/exports file is as follows:

/home/departments/sales sally.company.com (ro)

The statement indicates that the /home/departments/sales directory can be accessed by the host sally.company.com with read only privileges. Next start the NFS daemon with the “service nfs start” command.

On a remote client, a file can be manually accessed using the “mount” command, or managed by the OS using the “autofs” utility. The autofs utility automatically loads any files or directories a user has rights or access to. File shares can also be set up to automatically mount at when the OS starts up. The etc/fstab can be used to accomplish this task. The “fstab” file stands for file system table. This file lists all of the OS file system directories to be mounted by default. Of course the root user has access to and can alter this file.


0011. /etc/fstab

As stated above, fstab stands for file system table. According to Mark Sobell’s “A Practical Guide to Linux” the fstab file contains the list of file systems that the Linux host checks by default (Sobell, 601). The file is also used by the mount and umount utilities to mount or unmount directories. This file is located in the /etc directory. Here is an example of what an fstab entry looks like (note: the numbers underneath the fields are not part of the configuration file):

/dev/cdrom     /cdrom       iso9660    user,noauto,ro
#1 #2 #3 #4

As you can see the entry contains several fields. The first field gives the physical location of the file system. The location in the example is the CD-ROM drive. The second is the mount point of the file system. A mount point is physical location of the file system being mounted. The CD-ROM is being mounted to the /cdrom directory. The third field is the device or file system type. CD-ROMs use an iso9660 file system. The fourth field in the example gives any parameters to be used while mounting the file system. According to the example anyone can load the CD-ROM drive with read-only permissions.


0100. /etc/mtab

The /etc/mtab file lists all of the devices and files to be mounted when the OS boots. Clearly mtab stands for mount table. The “mount” command will display all mounted files and devices. Here is an example of an mtab entry (note: the numbers underneath the fields are not part of the configuration file):

/dev/hda        on        /        type    ext3    (rw)
#1
#2 #3 #4 #5

The first entry (#1) is the physical location of the mount. In this instance the root directory (field #2) is located on the primary IDE drive. Moreover, the /dev/hda is also the mount point for the root directory. The file system type is ext3 (fields #3 and #4) and the root file system was mounted with read and write file permissions (field #5).

As should be obvious, the /etc/mtab and /etc/fstab files are very similar in structure. Each file has entry lines that have several fields, both are used by the mount and umount utilities, and both contain mounting points for the directories and files being loaded.


0101.
Network Information Service (NIS)

NIS, formerly known as the Yellow Pages, allows important information to be distributed across a Linux network. For instance, password information, user groups, and individual network server information (IP addresses and hostnames) can all be shared between multiple Linux systems using a NIS server functioning as a centralized database. Like Network File System, NIS is set up in a client/server model.

There are several NIS tools used by the multiple Linux distributions. Most of the tools all begin with the letters “yp”, so they will be referred to as yp-tools from this point forward. The server must have multiple yp-tools available, while the client computers only need the client yp-tool(s).

The network services switch file (nsswitch.conf), contains the order that a host searches for information when it is requested. If NIS is used to lookup particular information on a network the nsswitch.conf file can be utilized to point to a NIS server as one of the locations to find information. Like all configuration files the nsswitch.conf file is located in the /etc directory and the NIS daemon must be started with the “service ypserv start” command. If NIS is being used to manage information about particular network hosts, for instance servers, the nsswitch.conf file must be configured.

NIS clients can be setup in multiple ways. The customary method is the edit the /etc/host.conf file. This file tells a host the order in which to resolve a search for files. Traditionally the configuration contains an entry to first search the computer and then to use the DNS server:

order hosts,bind

An entry must also be added to point to a NIS server:

order hosts,bind,nis


0110. Domain Name Service (DNS)

DNS is a very complex application with entire books written on the subject; this article merely skims the surface of this Internet tool. Only the files necessary to run the client and server services will be discussed.

When the Internet was small it was relatively easy to remember network addresses on the Internetwork. Of course that was eons ago, now it is practically impossible to remember the IP address of every host and domain name on the Internet. DNS is the solution to the problem. DNS is a service that resolves human readable domain names into IP addresses. This allows users to type in Universal Resource Locators (URL) like www.redhat.com/index.html instead of 209.132.177.50. In order for DNS to work a network must have a registered domain name.

There is a complex DNS system integrated into the Internet. It has a hierarchical structure, similar to the Linux file system. This hierarchy usually encompasses root and local network nameservers, although more complex networks could have additional tiers. The root nameservers house the databases for the top level domains (TLD). A TLD is the suffix located at the end of a domain name (i.e. .com, .net, .mil, etc.). Root DNS servers only accept requests from other nameservers.

Most domains (networks) will have a local nameserver that is responsible for the local network’s name resolution requests; in other words, local DNS servers are responsible for maintaining the database of hostnames requested by the local network. This database reduces the number of times a local nameserver has to seek out a root DNS server when a domain name has to be resolved. If a network does not have a physical DNS server, the domain more than likely uses an ISP’s nameserver(s).

Let us assume that the domain name, www.redhat.com/index.html, is being requested for the first time on a network. The resolution begins by interpreting the URL from right to left. There is an implicit “.” (period) at the end of the TLD which indicates to begin looking at the root of the DNS system. So DNS will start at the root nameserver of the TLD; in this instance the commercial (.com) name server. Next the Red Hat domain will be resolved. On the Red Hat domain the web server (www) host will be resolved, and the web server will supply the index.html webpage being requested. In other words the URL requests the index.html file located on the Red Hat domain’s web server.

There are several critical DNS files. On the DNS server, the /etc/named.conf file is the main configuration file. This is the file that an administrator will configure to get DNS functioning on the network. Directions on how to configure this file would require another article, so I will omit those instructions. Once the named.conf file has been configured, the “service named start” command should be administered from the command line in order to actually start the DNS service.

The /etc/hosts and the /etc/resolv.conf files must be configured for all DNS clients. The /etc/hosts file dictates how an address is resolved locally:

127.0.0.1 localhost.localdomain localhost
209.132.177.50 redhat.com

while the /etc/resolv.conf file defines which nameserver(s) to use:

nameserver 192.168.1.1
nameserver 200.200.173.1

DNS has multiple tools to manage the service. The “host” command is a DNS lookup tool. Basically the command allows users to identify nameservers. The “dig” command, like the host command, identifies nameservers; however, the tool is a bit more powerful. Several options can be used with the dig command to find specific information about a nameserver. This flexibility makes dig a great tool to use when troubleshooting DNS issues. Finally, the “nslookup” command allows a host to query Internet domain servers for information. The tool allows users to request information about the domain, the domain nameserver, and particular hosts on the domain. Indeed DNS is a powerful tool that makes navigation of the Internet feasible. With millions of hosts and domains on the Internet today it would be virtually impossible to manage them all without DNS.


0111. EOL

As with other articles, it is impossible to cover the full scope of the Linux OS. But hopefully it is obvious how powerful this multi-user OS is in the world of computers. It should also be apparent that the OS is multifaceted. In short, Linux is a powerful OS that allows users to have transparent access to all of the OS tools.


1000. Check Em’

A Practical Guide to Linux. Mark G. Sobell
Just For Fun: The Story of an Accidental Revolutionary. Linus Torvalds and David Diamond
http://www.redhat.com
http://linux.die.net/

1 comment:

Unknown said...
This comment has been removed by the author.