September 27, 2004

CLI Magic: Ifconfig

Author: Joe Barr

Want to learn something that will make your Windows-based friends squirm with feelings of geek-envy and inadequacy? Of course you do. Well, jump out of the GUI for bit and join us on the command line as we explore the magic of the ifconfig command.Ifconfig is one of the handiest tools around for tweaking your home network or resolving networking difficulties with your laptop while you're on the road. It's used in two ways: to display the status of your network devices and/or to configure those devices.

To display the status of all your network devices, enter "ifconfig -a" from the CLI. On my system, I need to either specify the complete path name ("/sbin/ifconfig -a") when I enter the command, or enter it as root. Root has different pathing than my user account and doesn't require the full path name to execute the program. Try this:


/sbin/ifconfig -a

My system replies:


eth0 Link encap:Ethernet HWaddr 00:FF:FF:FF:FF:FF
   inet addr:192.168.0.100 Bcast:192.168.0.255 Mask:255.255.255.0
   inet6 addr: fe80::250:8dff:fe4e:9dd0/64 Scope:Link
   UP BROADCAST NOTRAILERS RUNNING MULTICAST MTU:1500 Metric:1
   RX packets:244902 errors:0 dropped:0 overruns:0 frame:0
   TX packets:116938 errors:0 dropped:0 overruns:0 carrier:0
   collisions:0 txqueuelen:1000
   RX bytes:129738592 (123.7 Mb) TX bytes:12475215 (11.8 Mb)
   Interrupt:11 Base address:0xe800

lo Link encap:Local Loopback
   inet addr:127.0.0.1 Mask:255.0.0.0
   inet6 addr: ::1/128 Scope:Host
   UP LOOPBACK RUNNING MTU:16436 Metric:1
   RX packets:4021 errors:0 dropped:0 overruns:0 frame:0
   TX packets:4021 errors:0 dropped:0 overruns:0 carrier:0
   collisions:0 txqueuelen:0
   RX bytes:342543 (334.5 Kb) TX bytes:342543 (334.5 Kb)

sit0 Link encap:IPv6-in-IPv4
   NOARP MTU:1480 Metric:1
   RX packets:0 errors:0 dropped:0 overruns:0 frame:0
   TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
   collisions:0 txqueuelen:0
   RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)


Looking at the response for the first interface (eth0), we find all sorts of useful information.

The hardware address (called the MAC address) of the card on the first line
The IP address on the second line
The inet6 IP address on the third line
The status of the connection (UP) in the fourth line


Entering ifconfig without the -a argument lists only the active connections. In my case, the output would be identical to the first two interfaces (etho and lo) shown with the -a parameter. You can also ask for the status of only a single connection, by specifying the name of the interface you're interested in. On my system, that would give me a choice of "etho" or "lo."


You can change the status (up or down) of a device merely by appending the status to the command. To shut down my ethernet connection, I would enter ifconfig eth0 down. To bring it back up again, I would replace down with up.


You can use the ifconfig command to change almost any of the data shown, and some
things that we haven't seen yet. Have you ever worried about some lowlife scumbag putting a sniffer on your system and getting all your secrets? Ifconfig can help detect such nefarious activity, if it exists. Sniffers like to hear everything, so they put interfaces into "promiscuous mode," meaning they hear all traffic on the LAN, not just the traffic sent their way. Ifconfig tells you whether or not an interface is being promiscuous.


To illustrate that, let's use ifconfig to put the eth0 interface in promiscuous mode. The command to do that is ifconfig eth0 promisc. You may need to enter superuser mode (do the su thing) in order to change an interface configuration. Once you've accomplished that, use ifconfig eth0 to see the results. My system responds with the following as the 4th line of output:


UP BROADCAST NOTRAILERS RUNNING PROMISC MULTICAST MTU:1500 Metric:1


There it is, in big letters and bright lights. To get the interface out of promiscuous mode, simply repeat the ifconfig you used to put it there. The command is simply a toggle switch, changing from or to promiscuous mode depending on its status when the command is received.


If you ever need to change the IP address on your computer, it doesn't get much easier than doing it with ifconfig. Use ifconfig to take the interface down first, then give it the new IP address like this:


ifconfig eth0 192.168.0.22


Don't forget to bring the interface back up. Of course, doing this assumes you don't need to change anything other than the IP address. Covering all the bases on changing subnets, routing, and gateway is beyond the scope of this column.


The ifconfig command will also let you change the hardware address, broadcast address, and more. Need to set up a point to point link between your box and another one? Ifconfig is your friend, and it's a very powerful and useful one. As usual, there is much more to learn. You can get a good start on doing just that by perusing the man pages.

Click Here!