ifconfig in short “interface configuration” utility for system/network administration in Unix/Linux operating systems to configure, manage and query network interface parameters via command line interface or in a system configuration scripts.

Though there is a replacement command called ip command, ifconfig is still being used by most of people in IT world due to its popularity.

Here are some useful command examples:

1. View All Network Setting(one or all interfaces)

The “ifconfig” command with no arguments will display all the active interfaces details. The ifconfig command also used to check the assigned IP address of an server.

# ifconfig eth1
bond0     Link encap:Ethernet  HWaddr 00:1F:4F:A6:F9:50  
          inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MASTER MULTICAST  MTU:9000  Metric:1
          RX packets:257333960 errors:0 dropped:0 overruns:0 frame:0
          TX packets:99670997 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:16280855575 (15.1 GiB)  TX bytes:13677123809 (12.7 GiB)

2. Display Information of All Network Interfaces

The following ifconfig command with -a argument will display information of all active or inactive network interfaces on server. It displays the results for eth0, lo, sit0 and tun0.

# ifconfig -a | grep -e "Link"
bond0     Link encap:Ethernet  HWaddr 13:1F:4F:A6:F9:50   
eth0      Link encap:Ethernet  HWaddr 13:1F:4F:A6:F9:50   
eth1      Link encap:Ethernet  HWaddr 13:1F:4F:A6:F9:50   
eth2      Link encap:Ethernet  HWaddr 13:1F:4F:A6:F9:50   
eth3      Link encap:Ethernet  HWaddr 13:1F:4F:A6:F9:50   
eth4      Link encap:Ethernet  HWaddr 30:AB:21:7E:33:8D                                   
eth5      Link encap:Ethernet  HWaddr 30:AB:21:7E:33:8C  
eth6      Link encap:Ethernet  HWaddr 30:AB:21:7E:33:8F  
eth7      Link encap:Ethernet  HWaddr 30:AB:21:7E:33:8E  
lo        Link encap:Local Loopback  

3. Enable or Disable an Network Interface

The “up” or “ifup” flag with interface name (eth0) activates an network interface, if it is not in active state and allowing to send and receive information.

# ifconfig eth0 up
OR
# ifup eth0

On the other hand, the “down” or “ifdown” flag with interface name (eth0) deactivates the specified network interface. “ifconfig eth0 down” or “ifdown eth0” command deactivates the eth0 interface, if it is in active state.

# ifconfig eth0 down
OR
# ifdown eth0

4. How to Assign a IP Address to Network Interface

To assign an IP address to an specific interface, use the following command with an interface name (eth0) and ip address that you want to set. Set the IP address to interface eth0.

# ifconfig eth0 192.168.1.1

5. How to Assign a Netmask to Network Interface

Using the “ifconfig” command with “netmask” argument and interface name as (eth0) allows you to define an netmask to an given interface.

# ifconfig eth0 netmask 255.255.255.128

6. How to Assign a Broadcast to Network Interface

Using the “broadcast” argument with an interface name will set the broadcast address for the given interface.

# ifconfig eth0 broadcast 192.168.1.255

7. How to Change MTU for an Network Interface

The “mtu” argument set the maximum transmission unit to an interface. The MTU allows you to set the limit size of packets that are transmitted on an interface. The MTU able to handle maximum number of octets to an interface in one single transaction.

Note: Not all network interfaces supports MTU settings.

# ifconfig eth0 mtu 1000

8. Enable or Disable Promiscuous Mode

In normal mode, when a packet received by a network card, it verifies that the packet belongs to itself. If not, it drops the packet normally, but in the promiscuous mode is used to accept all the packets that flows through the network card.

Most of the today’s network tools uses the promiscuous mode to capture and analyze the packets that flows through the network interface. To set the promiscuous mode, use the following command.

# ifconfig eth0 promisc

To disable promiscuous mode, use the “-promisc” switch that drops back the network interface in normal mode.

# ifconfig eth0 -promisc

9. How to Add or Remove New Alias to Network Interface

The ifconfig utility allows you to configure additional network interfaces using alias feature. To add alias network interface of eth0, use the following command.

# ifconfig eth0:0 192.168.1.2

Next, verify the newly created alias network interface address, by using “ifconfig eth0:0” command.

# ifconfig eth2:0

eth2:0    Link encap:Ethernet  HWaddr 00:01:6C:99:14:68
          inet addr:192.168.1.2  Bcast:192.168.1.255  Mask:255.255.255.240
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:17

Remove Alias to Network Interface

# ifconfig eth0:0 down

Please note that alias network address in same sub-net mask.

10. Change the MAC address of Network Interface

To change the MAC (Media Access Control) address of an eth0 network interface, use the following command with argument “hw ether“.

# ifconfig eth0 hw ether AC:BD:CC:DD:EA:FF