Selasa, 11 Januari 2005

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

Jumat, 07 Januari 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.



Kamis, 06 Januari 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.

Minggu, 05 Desember 2004

Package Management using YUM

RedHat and other RPM based Linux distributions contain one drawback over distributions like Debian in that it is very hard to upgrade or install softwares because of dependency issues. And where Debian Linux has a very efficient and clean package management tool in the apt-get package which automatically resolves the dependency issues, redhat/ rpm based distributions lacked this. That was until yum came along. Yum stands for Yellowdog Updater, Modified for Redhat based distributions which is the counterpart of apt-get for Debian. Yum automatically computes dependencies and figures out what steps need to occur in order to install packages. It makes it much easier to maintain groups of machines without having to manually update each one using rpm.



Here I will explain how to install, uninstall and update individual packages in your Redhat Linux system. Before you start using yum, you have to modify the configuration file /etc/yum.conf. This is because the redhat repository server is severely overloaded and might be very slow. So it is in our interests to look at third party repositories. Here I will use mirrors.kernel.org as the alternate repository. So my edited /etc/yum.conf file reflecting the change is as shown below:



#File /etc/yum.conf



[main]

cachedir=/var/cache/yum

debuglevel=2

logfile=/var/log/yum.log

pkgpolicy=newest

distroverpkg=redhat-release

tolerant=1

exactarch=1

retries=20



[base]

name=Fedora Core $releasever - $basearch - Base

#baseurl=http://download.fedora.redhat.com/pub/fedora/ Linux/core/$releasever/$basearch/os/

baseurl=http://mirrors.kernel.org/fedora/core/$releasever/ $basearch/os/



[updates-released]

name=Fedora Core $releasever - $basearch - Released Updates

#baseurl=http://download.fedora.redhat.com/pub/fedora/ Linux/core/updates/$releasever/$basearch/

baseurl=http://mirrors.kernel.org/fedora/core/updates/ $releasever/$basearch/

As you can see, I have commented out the redhat fedora repository server and added the mirrors.kernel.org repository.

Also add the following two lines to the /etc/sysconfig/rhn/sources file.

yum fedora-core-1 http://mirrors.kernel.org/fedora/core/1/i386/os

yum updates-released http://mirrors.kernel.org/fedora/core/updates/1/i386
This is only for using our choosen repository with other redhat updation tools like up2date and rpm tools which also come with Fedora core 1 and above. Now you are ready to use yum.



Updating the RPM headers
(This has to be done at least once the first time before you start using yum).

This downloads the header files of the RPM packages from the repositories to your machine and will take only a couple of minutes to complete.

# yum check-update
Update all the packages installed on your system

# yum update
Update just an individual package (say gedit):

# yum update gedit
In the above case, if the gedit package installed on your system is the current version, yum will not do anything.

Install a package (say rdesktop) for the first time:

# yum install rdesktop
Suppose you have a package (say mplayer) installed and you would like a GUI interface to it. But you do not have any idea what the package might be called. You can find it out using the following command :

# yum search mplayer gui
And this is what you might see:

Gathering header information file(s) from server(s)

Server: Fedora Core 1 - i386 - Base

Server: Fedora Core 1 - i386 - Released Updates

Finding updated packages

Downloading needed headers

Looking in available packages for a providing package

Available package: mplayer-frontend.i386 2:3.48-1 from base matches with Gtk+ frontend for mplayer.

Available package: mplayer-frontend.i386 2:3.48-1 from base matches with mplayer-frontend
From the above output, you come to know that 'mplayer gui' package is known by the name mplayer-frontend. Now you can install the package as explained earlier. The search option also accepts wild card characters in the event you need to utilize them.

If you need a certain library which is not a standalone package like say libc6.1-1.so.2 . Just use the following command to search in which package, the particular library is in:

# yum provides libc6.1-1.so.2
You might get the following output:

Gathering header information file(s) from server(s)

Server: Fedora Core 1 - i386 - Base

Server: Fedora Core 1 - i386 - Released Updates

Finding updated packages

Downloading needed headers

Looking in available packages for a providing package

Available package: compat-libstdc++.i386 0:7.3-2.96.118 from base matches with

libstdc++-libc6.1-1.so.2

Available package: compat-libstdc++.i386 0:7.3-2.96.118 from base matches with

libstdc++-libc6.1-1.so.2(GCC.INTERNAL)

2 results returned

Looking in installed packages for a providing package

No packages found

... which tells that the library is in the compat-libstdc++ package which can be installed using

# yum install compat-libstdc++
To remove a package (say gedit):

# yum remove gedit
This removes the selected package as well as any other package that depends on it.

One thing worth noting is that when Yum downloads packages or updates for installation it does not remove them automatically from its disk cache, so some periodic maintenance is required.This is achieved as follows:

# yum clean all
The above command deletes any old cached packages from your system as well as removing any old rpm headers that are no longer needed.

Lastly if you want to get any additional information about a package (say xchat) without actually installing it, do the following :

# yum info xchat
As you can see, it is a piece of cake in managing packages using yum. To know more about this wonderful package management software, you may visit official yum project page or do

$ man yum


Jumat, 03 Desember 2004

Boost your hard drive performance in Linux using hdparm

Hdparm is a command-line utility that provides powerful control over your hard drive parameters (HD PARaMeters). It can also tell you a lot about your disk drive. Everything you do with hdparm, until you make a script for it, will be done at the command line. It can be adjusted manually and then put into a startup script to make your chosen settings effective every time the system starts up.

Suppose I want to improve the performance of my first hard disk drive - /dev/hda . The first thing I do is find out the characteristics of my hard disk. This can be done as follows:
# hdparm -i /dev/hda
And the output on my machine is this :
/dev/hda:
Model=QUANTUM FIREBALLlct10 10, FwRev=A03.0900, SerialNo=872007625887
Config={ HardSect NotMFM HdSw>15uSec Fixed DTR>10Mbs }
RawCHS=16383/16/63, TrkSize=32256, SectSize=21298, ECCbytes=4
BuffType=DualPortCache, BuffSize=418kB, MaxMultSect=16, MultSect=16
CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=20044080
IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}
PIO modes: pio0 pio1 pio2 pio3 pio4
DMA modes: mdma0 mdma1 mdma2
UDMA modes: udma0 udma1 *udma2
AdvancedPM=no WriteCache=enabled
Drive conforms to: ATA/ATAPI-4 T13 1153D revision 15: 1 2 3 4

* signifies the current active mode
In the output shown above, a few important values to be noted with interest are as follows:
  • MaxMultSect - The maximum number of sectors your hard disk can read at a time.
  • MultSect - The current number of sectors being read at a time.
  • PIO modes, DMA and UDMA modes - The modes supported by your hard drive. The one marked with an asterisk (*) is the one currently set.
  • AdvancedPM - Indicates whether or not your hard drive supports Advanced Power Management.
Another command :
# hdparm /dev/hda
will reveal the following information ...
/dev/hda:
multcount = 16 (on)
IO_support = 0 (default 16-bit)
unmaskirq = 0 (off)
using_dma = 1 (on)
keepsettings = 0 (off)
readonly = 0 (off)
readahead = 256 (on)
geometry = 19885/16/63, sectors = 20044080, start = 0
The items of interest in the above output are as follows:
  • multcount - The number of sectors being read at a time.
  • I/O support - The operating mode of your hard disk (16/32/32sync).
  • using_dma - Whether or not the drive is using the DMA feature. This may be on by default if your version of Linux properly detects and supports your chipset and drive's DMA capabilities.
  • keepsettings - Whether the settings are kept after the drive resets (usually caused by errors).
  • readonly - Whether the drive is read-only. Normally set to 1 only for CD-ROMs.
  • readahead - How many sectors ahead will be read when you access the hard drive.
The hdparm program provides two performance testing features that are crucial in letting you know whether or not you are improving performance or not as you tweak along.
# hdparm -Tt /dev/hda1
will show results such as the following before enhancing the performance.
/dev/hda1:
Timing buffer-cache reads: 340 MB in 2.01 seconds = 169.43 MB/sec
Timing buffered disk reads: 30 MB in 3.08 seconds = 9.73 MB/sec
and the results like these after enhancing the performance.
/dev/hda1:
Timing buffer-cache reads: 340 MB in 0.91 seconds = 200.00 MB/sec
Timing buffered disk reads: 30 MB in 1.05 seconds = 19.73 MB/sec
The goal is to see the time in seconds decrease and the MB/sec to increase in the above output.You can do that by using a variety of parameters, invoked one at a time, then rerunning the performance tests to see if things are improving or not.

For example: Begin by setting the operating mode of the interface between the system and the disk drive using one of the following parameters:
  • -c0 - Sets operating mode to 16-bits
  • -c1 - Sets operating mode to 32-bits
  • -c3 - Sets operating mode to 32-bits synchronized
Mode -c1 is usually used for best performance. Mode -c3 is required only for certain chipsets.
# hdparm -c1 /dev/hda
Next set the data transfer parameters, which you can determine from the -i command shown earlier. In the above case, the value of MaxMultSect is 16 which is the maximum supported.
# hdparm -m16 /dev/hda
Next try activating DMA mode for your system interface:
# hdparm -d1
Then set the drive mode (a value of X32 is most common; UDMA-5 is X69):
# hdparm -X32 /dev/hda
Finally, try setting the read-ahead value, which is typically set to the same value as multcount from earlier (See the hdparm /dev/hda output above), or 16:
# hdparm -a16 /dev/hda
If any or all of these settings make incremental improvements in performance, remember them and create a script that sets them all sequentially or includes them all in one line.

From all these settings, you might be using the following optimal single command :
# hdparm -X34 -m16 -c1 -a16 -d1 /dev/hda
Now save this command into a file and make the file into a script and place in the directory for the runlevel at which you normally use linux. I use runlevel 2 by default on my home machine. So I create a file named /etc/init.d/hdparm.local with the above hdparm command. Then configure it to start at runlevel 2 as follows:
# ln -s /etc/init.d/hdparm.local /etc/rc2.d/S20hdparm.local
Update (Oct 26 2007): If you are using Ubuntu or any Debian based Linux distribution, you can set the hdparm command and its options in the /etc/hdparm.conf configuration file instead of creating the above mentioned script and saving it in init.d directory. Also note that in Ubuntu Gutsy Gibbon, even the IDE drives are provided device nodes with name /dev/sda instead of /dev/hda. So make the necessary changes while executing the commands.

The next step is to keep an eye on dmesg and/or /var/log/syslog. In some cases, an error will cause the settings to be reset. So that's where the -k (keep) flag comes in. If you are 100% positive that these settings won't corrupt your data, you can add -k to the script.

WARNING : Setting hdparm parameters too aggressively - that is, in excess of the disk controller or drive capabilities - can lead to data loss. It is best to test hdparm settings on a fresh installation of the operating system before committing any applications or programs to the drive and prepare to back down on the settings and reinstall the OS if the drive is unstable or the hdparm tests show erratic results or fail.

Rabu, 01 Desember 2004

Popular Linux Links

I come across loads of linux links while searching for stuff related to linux. I share some of the websites which I found to be interesting below.

LinuxHomeNetworking - This site contains a whole lot of tutorials on configuring various aspects of linux like setting up Quotas for users, DNS configuration, sendmail configuration and most things related to networking. A very good site to pick up the skills in configuring various networking related linux softwares.

TLDP.Org - This site is maintained by a loosely knit team of volunteers who provide documentation for many aspects of Linux. There are several forms of documentation: Guides, HOWTOs, man pages, and FAQs.This is one of the first places to look when you encounter a problem related to linux.

LinuxSecurity.com - This site deals with issues related to security in linux. It has the latest news, advisories, resources like white papers, HowTo's, security dictionary and newsletters.

LinuxQuestions.org - This is a linux forum where you can post your questions based on linux and get them answered by visitors to this site. Even if you are not interested in posting your question, it would be worth your time, if you browse through posts on this high traffic site. A number of times when I googled for linux related topics, I got this site consistently in the first page of the search - which speaks volumes about the popularity of this site.

L.O.S.T - A site which hosts user contributed tips on getting various jobs done in linux. The tips can be eaither downloaded as a fortune database or can be viewed online.

Linux Devcenter - This is an O'Reilly site which has lots of articles on linux. This site is specifically targeted at developers. But anybody interested in linux can gain something by visiting this site.

Kernel.org - This is the primary site for the Linux kernel source. If you are interested in downloading patches for your kernel or getting the latest kernel source, then this is the site to visit.

www-130.ibm.com - This is IBM's linux resource site for developers. Here you can obtain a wealth of tutorials and articles on configuring, administering and using linux and linux based softwares.

Linux Magazines

Redhat Magazine - An online magazine brought out by redhat. This magazine publishes articles related to redhat enterprise linux and fedora.

LinuxGazette.net - A monthly magazine dedicated to linux which can be downloaded in a variety of formats for offline viewing. I really like their 'Ask the Answer Gang' and 'MailBag' sections.

LinuxGazette.com - This is the counterpart of the linuxgazette.net magazine whose team split into two because of the difference in opinion between them. You can post your articles and questions in its forum after you have registered with their site.

LinuxFocus.org - The goal of LinuxFocus is to produce and publish a free online magazine about Linux and related issues in a number of languages. LinuxFocus is an open magazine, it is the joint effort of many people. Anyone can contribute interesting articles.

Linux-Mag - This is another online magazine which has loads of articles and tips on linux for both the newbies and the linux guru's alike.

LinuxHotBox - This is a linux eMagazine which you can download and read offline. Has quite good subject matter though the magazine itself is over a few MB's download which could be tough on dialup users. Ironically, they only have a windows exe version of their ebook for download.

Online Books

Rute - A great, must read, online book on linux. You can also get the printed version of this book.

Safari.OReilly.com - This is the online library of O'Reilly - the biggest computer book publishers in the world. You get to read most linux books published by O'Reilly here. It is basically a paid service but you can try safari free for 14 days.

These are only a few of the interesting sites I came across. You can get more linux related links on the right side bar of this site under the section 'My Linux Bookmarks'.