Learn to use ifconfig by example

command 'ifconfig' is used to config a network interface.

Here we list a few cases that might be frequently used.

List the network interface information.
 

Our example machine is Dublin who has one 3com NIC card which is running, 2 DECchip tulip NIC cards which are not set well yet.

1. without any option, any argument, ifconfig lists only the interfaces that are working.

[root@dublin /root]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:B0:D0:D8:FE:09 
          inet addr:132.177.8.28  Bcast:132.177.8.127  Mask:255.255.255.128
          inet6 addr: fe80::2b0:d0ff:fed8:fe09/10 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:45414 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7441 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100
          Interrupt:5 Base address:0xe880

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:6 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0

1.5 Apply "ifconfig" on one NIC interface will display that interface info

[root@dublin /root]# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:B0:D0:D8:FE:09 
          inet addr:132.177.8.28  Bcast:132.177.8.127  Mask:255.255.255.128
          inet6 addr: fe80::2b0:d0ff:fed8:fe09/10 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:46123 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7512 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100
          Interrupt:5 Base address:0xe880

 
2. with option -a, ifconfig lists all possible network interfaces( including virtual interfaces ).

[root@dublin /root]# ifconfig -a
eth0      Link encap:Ethernet  HWaddr 00:B0:D0:D8:FE:09 
          inet addr:132.177.8.28  Bcast:132.177.8.127  Mask:255.255.255.128
          inet6 addr: fe80::2b0:d0ff:fed8:fe09/10 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:45796 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7487 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100
          Interrupt:5 Base address:0xe880

eth1      Link encap:Ethernet  HWaddr 00:C0:F0:6A:56:51 
          BROADCAST MULTICAST  MTU:1500  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:100
          Interrupt:10 Base address:0x4c00

eth2      Link encap:Ethernet  HWaddr 00:C0:F0:6A:6D:0C 
          BROADCAST MULTICAST  MTU:1500  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:100
          Interrupt:11 Base address:0x6800

gre0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 
          NOARP  MTU:1476  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

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:6 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0

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

teql0     Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 
          NOARP  MTU:1500  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:100

tunl0     Link encap:IPIP Tunnel  HWaddr  
          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


The above command is running on latest kernel 2.4.10 which includes all possible networking options. interfaces other than eth* are virtual interfaces.

Here we see that eth1 and eth2 are down.

You may need to insert the NIC card modules before you see eth1, eth2.
(login as root and use "insmod tulip" to install NIC driver to kernel )


3. To assign ip address for the Ethernet card

#ifconfig eth1 192.168.2.1 netmask 255.255.255.0  up
#ifconfig eth1

eth1      Link encap:Ethernet  HWaddr 00:C0:F0:6A:56:51 
          inet addr:192.168.2.1  Bcast:192.168.2.255  Mask:255.255.255.0
          inet6 addr: fe80::2c0:f0ff:fe6a:5651/10 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:1 dropped:0 overruns:0 frame:0
          TX packets:0 errors:2 dropped:0 overruns:0 carrier:2
          collisions:0 txqueuelen:100
          Interrupt:10 Base address:0x4c00

IP address is set up and brought successfully


4. To disable on NIC interface

#ifconfig eth1 down
# ifconfig eth1    

eth1      Link encap:Ethernet  HWaddr 00:C0:F0:6A:56:51 
          inet addr:192.168.2.1  Bcast:192.168.2.255  Mask:255.255.255.0
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:1 dropped:0 overruns:0 frame:0
          TX packets:2 errors:2 dropped:0 overruns:0 carrier:2
          collisions:0 txqueuelen:100
          Interrupt:10 Base address:0x4c00

4. To bring up a NIC interface

#ifconfig eth1 up


For more information on command "ifconfig", See man page