Sunday, 30 January 2005

NFS Client - Server Configuration

NFS - Network File Service - is a System V managed service which is basically used to serve files from a remote computer to your local machine. It consists of two parts; the server part and the client part.



The Server Configuration:

Two main RPM packages are needed to configure NFS as a server on your RedHat machine:

portmap - needed because NFS server is an RPC (Remote Procedure Call) service.

nfs-utils - Which contains the essential files and utilities like the exportfs, showmount, scripts installed in the /etc/rc.d/init.d/ directories like nfs etc which form a part of the NFS server.



The NFS server software is depended on three facilities for its work:

  • portmap : Which maps the calls made from the other machines to the correct RPC service.
  • nfs (in kernel): Translates NFS requests into requests on the local filesystem and
  • rpc.mountd : Which mounts and unmounts filesystems.

All the above three run as daemons and are started at boot time from the portmap and nfs System V initialization scripts. See /etc/rc.d/init.d/ directory.



To verify that these services are running, do eaither of the following:

# rpcinfo -p
OR

# service nfs status

# service portmap status
To verify that these services are running on a remote server (say myserver), do:

# rpcinfo -p myserver
Once you have made sure the above services are running, the next step is to decide which all directories and filesystems are to be made available for sharing across the network via NFS.

This is listed in the /etc/exports file.

#FILE: /etc/exports

/engineering *.myserver.com(ro,sync) otherserver.india.com(rw,sync)

/root/presentations macmot.dc.com(rw,sync)

/sales 192.168.10.0/255.255.255.0(sync)
The above listing is a part of my /etc/exports file. Each line contains one exported directory and its access permissions. For example, the first line exports the /engineering directory to all the clients in the 'myserver.com' domain with read-only access and 'otherserver.india.com' with read-write access. And the data is synchronized on to the disk on each access. The third line shows that you can also give a valid IP address/subnet mask to specify a range of addresses to which the particular directory is exported.

Note: You can use wild cards like * and ? for the purpose. Care should be taken to see that the options are not seperated from the hostnames with white space. If white space exists between a hostname and an option, it is treated as two distinct export destinations and the option will apply to a "world export".



Another thing of significance is that all entries in the /etc/exports are exported with root_squashing turned on. This ensures that a person having root access on a remote machine is not given root access to the files in the server machine.This can be negated by using the no_root_squash option.



Once you have finished editing the /etc/exports file, you have to make the NFS server read the /etc/exports file. This you can do eaither by rebooting the machine or you can run the command :

# exportfs -a
This exports all the shares listed in the /etc/exports file to the NFS server. You have to run this command each time you make changes to the /etc/exports file.

You can check the proper operation of your NFS server by running eaither of the two commands:

# exportfs -v
OR

# service nfs status
Client side configuration :

The main job here is to mount the NFS share exported by the remote computer (let us say server_one). This can be achieved by a few different ways:

  1. Specify it in the /etc/fstab file.
  2. Use the autofs daemon to mount NFS shares on demand and unmount them when idle.
  3. You can mount the NFS shares manually as root, using the mount command.

But before that, you have to know which are the directories exported by the remote NFS server. This is achieved by the command:

# showmount -e
Where hostname is the remote NFS server hostname. When you mount an exported directory from an NFS server, you can access it as if it were local to your machine.

#File: /etc/fstab

server_one:/sales /mnt/pub nfs defaults 0 0
The above listing shows that the /sales directory from the NFS server server_one is mounted locally at /mnt/pub directory. The /etc/rc.d/init.d/netfs script will mount any network filesystems that are configured to be mounted at boot time such as the /etc/fstab listing above.



Some NFS specific options that can be used with mount or in /etc/fstab include:

  • rsize=8192 and wsize=8192 - will speed up NFS thoughtput considerably.
  • soft - Processes return with an error on a failed I/O attempt.
  • hard - will block a process that tries to access an unreachable share.
  • intr - allows NFS requests to be interrupted or killed if the server is unreachable.
  • nolock - Disables file locking (lockd) and allows interpolation with older NFS servers.

For example:

# mount -t nfs -o rsize=8192,wsize=8192,soft,rw server_one:/sales /mnt/sales
The kernel automounter facility, autofs, provides the ability to mount the NFS shares on demand and unmount them when they are idle in a way that is transparent to the end user. Check whether you have the autofs RPM installed in your machine. Then turn it on using the command:

# chkconfig autofs on
Now edit the file /etc/auto.master to mirror your configuration. Check man auto.master for the details of the syntax. Lastly start the autofs service:

# service autofs start
Note: You have to restart the autofs daemon each time you make changes to the /etc/auto.master file. Now you have successfully configured the NFS server and client.

Tuesday, 11 January 2005

Changing the hostname on your machine

This can be achieved in three steps.

1) Issue the command :

root# hostname new-host-name
2) Change the network configuration file /etc/sysconfig/network to include the line :

HOSTNAME=new-host-name
3) Restart the systems which relied on the hostname (or reboot):
root# service network restart
Restart desktop

i) Bring down system to console mode :

root# init 3


ii) Bring up X Windows:

root# init 5


One may also want to check the file /etc/hosts for an entry using the system name which allows the system to be self aware.



How to install a Network card in linux

There are different ways of installing a network card in linux - and that too depending on the linux distribution that you are using. I will explain each one of these methods here.

The Manual method


Open the computer case and insert the network card into an empty PCI slot. Then boot up your machine to load linux.

In linux login as root and then navigate to the directory /lib/modules/kernel_version_number/net/ . Here you will find the modules supported by your system. Assuming that you have a 3Com ethernet card, in which case, the module name is 3c59x , you have to add this in the /etc/modules.conf file to let the machine detect the card each time the machine boots.

#File: /etc/modules.conf
alias eth0 3c59x

Note: If you have only one network card, it is known by the name eth0, the succeeding network cards in your computer go by the name eth1, eth2 ... and so on.

Now you have to load the module into the kernel.

root# /sbin/insmod -v 3c59x

Next configure an IP address for the network card using ifconfig or netconfig or any other method if your machine gets its IP address from a DHCP server. Eg:

root# ifconfig eth0 192.168.1.5 netmask 255.255.255.0 broadcast 192.168.1.255

The Easy way


RedHat/Fedora distributions of linux ships with Kudzu a device detection program which runs during systems initialization (/etc/rc.d/init.d/kudzu). This can detect a newly installed NIC and load the appropriate driver. Then use the program /usr/sbin/netconfig to configure the IP address and network settings. The configuration will be stored so that it will be utilized upon system boot.

Also see Assigning an IP address to know more ways of configuring an IP address for your network card.

How to Assign an IP address in RedHat

Computers may be assigned a static IP address or assigned one dynamically (via DHCP). Here I will explain the steps needed to assign an IP address to your NIC.

Choose one of the following methods:

Using ifconfig command line tool


# ifconfig eth0 192.168.1.3 netmask 255.255.255.0 broadcast 192.168.1.255

In the above command, 192.168.1.3 is your machine's IP address, 255.255.255.0 is the netmask and 192.168.1.255 is your broadcast address.
The ifconfig command does not store these changes permanently. Upon reboot this information is lost. To make your changes permanent, manually add the commands to the end of the file /etc/rc.d/rc.local to execute them each time during boot up.

Using GUI tool - neat


You can use the GUI tool /usr/bin/neat - Gnome GUI network administration tool. It handles all interfaces and configures for both static assignment as well as dynamic assignment using DHCP.

Using netconfig console tool


You can open a terminal and run the command line tool /usr/sbin/netconfig to configure your machine's IP address in RedHat. The caveat is that it only seems to work for the first network interface aka eth0.

The command netconfig and /usr/bin/neat make permanent changes to system network configuration files located in /etc/sysconfig/network-scripts/, so that this information is retained.

The RedHat configuration tools store the configuration information in the file /etc/sysconfig/network. They will also allow one to configure routing information.

Static IP address configuration


To assign a static IP address to your machine running RedHat, edit the file /etc/sysconfig/network with the following details.
NETWORKING=yes
HOSTNAME=my-hostname
FORWARD_IPV4=true
GATEWAY="XXX.XXX.XXX.YYY"

Where my-hostname is the hostname of your machine. FORWARD_IPV4 value is true for NAT, firewall, gateways and linux routers. False for everyone else like desktops and servers. GATEWAY option is used if your network is connected to another network or the internet.

Assigning an IP address via DHCP


For configuring your machine to be assigned an IP address via DHCP, edit the /etc/sysconfig/network file with the following details.
NETWORKING=yes
HOSTNAME=my-hostname

Note: Gateway is assigned by DHCP. So unlike for static IP configuration, you do not have to assign it here specifically.

Setting IP address using file ifcfg-eth0


Open the file /etc/sysconfig/network-scripts/ifcfg-eth0 and enter the following information.

Static IP configuration
 
DEVICE=eth0
BOOTPROTO=static
BROADCAST=XXX.XXX.XXX.255
IPADDR=XXX.XXX.XXX.XXX
NETMASK=255.255.255.0
NETWORK=XXX.XXX.XXX.0
ONBOOT=yes

DHCP configuration

DEVICE=eth0
ONBOOT=yes
BOOTPROTO=dhcp

Once you have made changes to the files above, you can make the network card use the new values without any reboot by running the following command.

# ifup eth0

ifup is a script residing in /etc/sysconfig/network-scripts/ifup, which is used to bring network interfaces on-line.

Note: To disable DHCP change BOOTPROTO=dhcp to BOOTPROTO=none in the ifcfg-eth0 file above.

In order for updated information in any of these files to take effect, one must issue the command:
# service network restart

Friday, 7 January 2005

Installing a new hard drive in your PC running Linux

If you have brought a brand new hard drive and wish to install it in your computer running linux, these are the steps to follow:

Assuming that you have already physically attached the hard drive into your PC, boot up your machine and when linux loads, log in as root. Since this is your second hard drive, it's device name will be /dev/hdb if it is a IDE drive and /dev/sdb if your hard disk is a SCSI disk. I am assuming that it is an IDE drive which is the most commonly used in home PCs.

You can use the fdisk utility in linux to view the partition information as well as create, modify or delete the existing partitions in the new hard disk. To view the partition information, execute :

root# fdisk -l /dev/hdb
If no partitions are seen, then you have to create them. For that, you can use eaither fdisk itself or another more user friendly program called QTParted.

QTParted creates, deletes, and non-destructively moves and resizes partitions (even NTFS). So, you can make room to copy your data without losing anything.If you have QTParted installed on your machine, then I would recommend using it as it is much safer.

Here I will explain the fdisk way of creating a partition. It is medium safe to play around with fdisk as changes are not written to disk until you give the command to do so. This sequence of commands create a single partition.

root# fdisk /dev/hdb
Type "m" at anytime to display a table of fdisk commands. Then type "n" to create a new partition. Now type "p" to create a primary partition. Your disk can have from 1 to 4 primary partitions. Hit Enter twice to accept the defaults. Or if you don't want to use the whole disk, hit Enter once to accept the default starting point, then select the size you want:

+1000M
Hit "p" anytime to preview the new partition table. When you are satisfied with the partitions created, press "w" to write the changes to disk. By default, fdisk creates a type 83 partition, which means linux partition. To see a list of partition types, press "l". To change the partition type, press "t". To delete an existing partition, press "d" and follow the prompts.

After you have created the partitions and exited fdisk, the next step is to format the disk for the file system of your choice. This is done with the mkfs utilities.For example, if you want to create an ext2 filesystem on the newly formated hard disk, execute the command:

root# mkfs.ext2 -c /dev/hdb1
Note: Since I have created only one partition on the entire hard disk, the partition is named /dev/hdb1. If you had created another primary partition, then the second partition would have been /dev/hdb2 and so on. And if instead of a second primary partition, you had created a logical partition, it would have been named /dev/hdb5.

If instead of an ext2, you wanted to create an ext3 partition, then execute the command:

root# mke2fs -j -c /dev/hdb1
-j specifies journaling support. To create a reiser filesystem:

root# mkreiserfs /dev/hdb1
I hope you are getting the idea. Now the last step is to mount the partition so that you can start saving data in your new hard disk. For that execute the command :

root# mount -t ext3 -o rw /dev/hdb1 /mnt/hdb1
The above command mounts the /dev/hdb1 partition on the mount point /mnt/hdb1. The "-t" flag says that the partition is of type ext3 and the -o flag specifies that it has to be mounted as "rw" read-write.

To unmount the partition, type the command:

root# umount /mnt/hdb1
Now each time when you boot into linux, if you want the new hard disk to be mounted by the OS automatically, then you have to include (add) the following line in your /etc/fstab file:

#File: /etc/fstab

/dev/hdb1 /mnt/hdb1 ext3 auto,users,exec 0 0
The above line mounts the partition at mount point /mnt/hdb1 as type ext3.

Now you have finished installing the new hard disk in your linux machine.



Thursday, 6 January 2005

Interview with Mr. Richard .M.Stallman

I came across an interview with Richard M Stallman - The free software evangelists. Richard.M.Stallman had founded the GNU Project in 1984, and the Free Software Foundation in 1985. He also originally authored a number of well known and highly used development tools, including the GNU Compiler Collection (GCC), the GNU symbolic debugger (GDB) and GNU Emacs.

The interview moves through the early years of Mr Stallman's life as a programmer, the philosophy of free software movement, to the issues faced by GNU/Linux - the patent problem, the negative effects of non-free software, the SCO law suit etc. Infact, the interview covers the whole gamut of issues faced by the Free Software Movement as well as what the future holds for people who value their freedom w.r.t the use of Information Technology related products. The interview has been conducted by Jermey Andrews and he has done a good job in presenting the questions.

This is a very interesting read for anyone interested in the GNU movement.