i'm done watching this

November 20, 2006

Ifconfig - dissected and demystified

ifconfig - the ubiquitous command bundled with any Unix/Linux OS is used to setup any/all the network interfaces such as ethernet, wireless, modem and so on that are connected to your computer. ifconfig command provides a wealth of knowledge to any person who takes the time to look at its output. Commonly, the ifconfig command is used for the following tasks:

1) Configuring an interface - be it ethernet card, wireless card, loop back interface or any other. For example, in its simplest form, to set up the IP address of your ethernet card, you pass the necessary options to the ifconfig command as follows:
# ifconfig eth0 netmask broadcast up
Where the number pertains to the IP address of your machine. I have used a private IP address. denotes the network mask which decides the potential size of your network and the number denotes the broadcast address and lastly, the 'up' keyword is the flag which loads the module related to this particular ethernet card and makes it ready to receive and send data.

2) Gathering data related to the network off which our computer is a part.
When used without any parameters, the command ifconfig shows details of the network interfaces that are up and running in your computer. In my machine which has a single ethernet card and a loop back interface, I get the following output.

eth0 Link encap:Ethernet HWaddr 00:70:40:42:8A:60
inet addr: Bcast: Mask:
RX packets:160889 errors:0 dropped:0 overruns:0 frame:0
TX packets:22345 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:33172704 (31.6 MiB) TX bytes:2709641 (2.5 MiB)
Interrupt:9 Base address:0xfc00

lo Link encap:Local Loopback
inet addr: Mask:
RX packets:43 errors:0 dropped:0 overruns:0 frame:0
TX packets:43 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3176 (3.1 KiB) TX bytes:3176 (3.1 KiB)
As you can see, it throws up a lot of data, most of it providing one detail or another. Lets look at the data spewed out by the ifconfig command one by one for the ethernet device.
  • Link encap:Ethernet - This denotes that the interface is an ethernet related device.
  • HWaddr 00:70:40:42:8A:60 - This is the hardware address or MAC address which is unique to each ethernet card which is manufactured. Usually, the first half part of this address will contain the manufacturer code which is common for all the ethernet cards manufactured by the same manufacturer and the rest will denote the device Id which should not be the same for any two devices manufactured at the same place.
  • inet addr - indicates the machine IP address
  • Bcast - denotes the broadcast address
  • Mask - is the network mask which we passed using the netmask option (see above).
  • UP - This flag indicates that the kernel modules related to the ethernet interface has been loaded.
  • BROADCAST - Denotes that the ethernet device supports broadcasting - a necessary characteristic to obtain IP address via DHCP.
  • NOTRAILERS - indicate that trailer encapsulation is disabled. Linux usually ignore trailer encapsulation so this value has no effect at all.
  • RUNNING - The interface is ready to accept data.
  • MULTICAST - This indicates that the ethernet interface supports multicasting. Multicasting can be best understood by relating to a radio station. Multiple devices can capture the same signal from the radio station but if and only if they tune to a particular frequency. Multicast allows a source to send a packet(s) to multiple machines as long as the machines are watching out for that packet.
  • MTU - short form for Maximum Transmission Unit is the size of each packet received by the ethernet card. The value of MTU for all ethernet devices by default is set to 1500. Though you can change the value by passing the necessary option to the ifconfig command. Setting this to a higher value could hazard packet fragmentation or buffer overflows. Do compare the MTU value of your ethernet device and the loopback device and see if they are same or different. Usually, the loopback device will have a larger packet length.
  • Metric - This option can take a value of 0,1,2,3... with the lower the value the more leverage it has. The value of this property decides the priority of the device. This parameter has significance only while routing packets. For example, if you have two ethernet cards and you want to forcibly make your machine use one card over the other in sending the data. Then you can set the Metric value of the ethernet card which you favor lower than that of the other ethernet card. I am told that in Linux, setting this value using ifconfig has no effect on the priority of the card being chosen as Linux uses the Metric value in its routing table to decide the priority.
  • RX Packets, TX Packets - The next two lines show the total number of packets received and transmitted respectively. As you can see in the output, the total errors are 0, no packets are dropped and there are no overruns. If you find the errors or dropped value greater than zero, then it could mean that the ethernet device is failing or there is some congestion in your network.
  • collisions - The value of this field should ideally be 0. If it has a value greater than 0, it could mean that the packets are colliding while traversing your network - a sure sign of network congestion.
  • txqueuelen - This denotes the length of the transmit queue of the device. You usually set it to smaller values for slower devices with a high latency such as modem links and ISDN.
  • RX Bytes, TX Bytes - These indicate the total amount of data that has passed through the ethernet interface either way. Taking the above example, I can fairly assume that I have used up 31.6 MB in downloading and 2.5 MB uploading which is a total of 37.1 MB of bandwidth. As long as there is some network traffic being generated via the ethernet device, both the RX and TX bytes will go on increasing.
  • Interrupt - From the data, I come to know that my network interface card is using the interrupt number 9. This is usually set by the system.
The values of almost all the options listed above can be modified using the requisite ifconfig options. For example, you can pass the option 'trailers' to the ifconfig command to enable trailer encapsulation. Or you can change the packet size by using the 'mtu' option along with the new value and so on. But in majority of the cases, you always accept the default values.

Learning to use the right command is only a minuscule part of the job of a network administrator. The major part of the job is in analyzing the data returned by the command and arriving at the right conclusions.