These classnotes are depreciated. As of 2005, I no longer teach the classes. Notes will remain online for legacy purposes

UNIX01/Ifconfig Overview

Classnotes | UNIX01 | RecentChanges | Preferences

Ifconfig is used to configure the kernel-resident network interfaces. It is used at boot time to set up interfaces as necessary. After that, it is usually only needed when debugging or when system tuning is needed.

If no arguments are given, ifconfig displays the status of the currently active interfaces. If a single interface argument is given, it displays the status of the given interface only; if a single -a argument is given, it displays the status of all interfaces, even those that are down. Otherwise, it configures an interface.

Ifconfig is usually located in /sbin/ifconfig, thus it is not typically in the path of normal users. That being said, unless you configure otherwise, non-root users can still run the program to obtain status information about the networking devices connected to the system.

Running ifconfig with no command line arguments could yeild something which looks like this:

 sam@rygel:~$ /sbin/ifconfig 
 eth0      Link encap:Ethernet  HWaddr 00:02:2A:C2:45:7F  
          inet addr:68.0.151.209  Bcast:68.0.151.255  Mask:255.255.248.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:28952 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2536 errors:0 dropped:0 overruns:0 carrier:0
          collisions:195 txqueuelen:100 
          RX bytes:5590005 (5.3 MiB?)  TX bytes:305003 (297.8 KiB?)
          Interrupt:10 Base address:0x3000 

 lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:110 errors:0 dropped:0 overruns:0 frame:0
          TX packets:110 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:57073 (55.7 KiB?)  TX bytes:57073 (55.7 KiB?)

As you can see, it provides a lot of information. The ifconfig command by itself is very useful for debugging a troubled network configuration. If, for example, our ethernet device was not working, running ifconfig would tell us so:

 sam@outbackjr:~$ /sbin/ifconfig 
 lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:110 errors:0 dropped:0 overruns:0 frame:0
          TX packets:110 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:57073 (55.7 KiB?)  TX bytes:57073 (55.7 KiB?)

Using ifconfig to configure a network device

As an administrator, you can manually configure a network device using ifconfig. The syntaxt for ifconfig when run this way is as follows:
 ifconfig <interface> <ip_address> [ netmask <netmask> ]

Where:

  • <interface> = the network interface you want to configure (eth0, eth1... and so on)
  • <ip_address> = the ip address you want to assign to the interface (example: 1.1.1.1)
  • <netmask> = the subnet mask of your assigned network (example: 255.255.255.0)

For example, if I wanted to configure my system to have an IP address of 68.0.151.209 with a netmask of 255.255.248.0, then the command would be

 # ifconfig eth0 68.0.151.209 netmask 255.255.248.0

Once I have done that, I need to establish a route to my gateway, so that I am able to connect to outside networks from my own (i.e. Internet). I know that the IP address for my gateway machine is 68.0.144.1 and I just set up my first interface, eth0. eth0 is the interface that I want to tie the route to. The command I can type to get my route established is:

  # route add default gw 68.0.144.1 eth0

This is the way networking interfaces are added to Linux, in fact, the loopback interface is added in a very similar way:

  # ifconfig lo 127.0.0.1
  # route add -host 127.0.0.1 lo

Fortunately for us, we will practically never have to enter these commands by hand. In a functionning Linux system, these commands will be issued for us by the init scripts at boot. However, it is important to understand how these items work so that we can troubleshoot problematic init scripts or set up our own routing systems.

NOTE: route has many more uses than simply adding new routing for local system gateways. We examine these in the second course (UNIX02/ARP Tables And Routing)

NOTE 2: ifconfig is a command that is pretty common amongst UNIX systems. However, its usage can vary dramatically from flavor to flavor. If in doubt, always consult the man page! ifconfig for Linux will be examined in much more detail in UNIX02/Ifconfig And Netstat.


Classnotes | UNIX01 | RecentChanges | Preferences
This page is read-only | View other revisions
Last edited August 1, 2003 11:31 pm (diff)
Search:
(C) Copyright 2003 Samuel Hart
Creative Commons License
This work is licensed under a Creative Commons License.