In Linux, ifconfig command is used to display and work on interfaces. This is an interface utilities that could used to work on Unix/Linux operating systems to manage interface.

In another post, we also saw how we could work with Linux IP command, which is also used to mange Linux interfaces even more advanced way

It could show all interfaces with its current configured network settings and also provide feature to manage it further like to assign IP address, netmask or broadcast address on interfaces, creating and deleting network aliases etc.
Let discuss some of examples of ifconfig commands that we could do with it.

Show Interface

So ifconfig without any argument will show only active interface details on screen, So most of linux User/Admin uses this command to check linux systems IP, netmask etc

# ifconfig 
eth0      Link encap:Ethernet  HWaddr 24:2A:97:72:DE:F0  
          inet addr:10.24.124.120  Bcast:10.24.124.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3096601 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1494488 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:3068210005 (2.8 GiB)  TX bytes:188309812 (179.5 MiB)

eth1      Link encap:Ethernet  HWaddr 24:2A:97:72:DE:F1  
          UP 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:1000 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:495 errors:0 dropped:0 overruns:0 frame:0
          TX packets:495 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:73810 (72.0 KiB)  TX bytes:73810 (72.0 KiB)

If Interface is up , doesn’t mean that it has cable connected and ip is assigned on it to connect other machine. It only through OS, this interface is UP.
Interface assigned with configured IP address and cable connected will not able to communicate with any machine if not enable or UP through OS.

Enable or disable Interface

you can enable or UP interface through OS with simple below commands.

ifconfig eth1 up

ifconfig eth2 down

In case you need to see all interfaces on machine, we could use -a option with ifconfig command with like below.

# ifconfig -a

In case you need to view only one interface then we could use ifconfig command with specific interface.

# ifconfig  eth0 
eth0      Link encap:Ethernet  HWaddr 24:3A:97:23:C9:00  
          inet addr:10.24.124.248  Bcast:10.24.124.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:5335684 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3246515 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:4134415333 (3.8 GiB)  TX bytes:409034809 (390.0 MiB)

But it only work with one interface not more one interface.

Assign Ip address

You could able to assign interface Ip address on interfaces through ifconfig command like below.

# ifconfig  eth1 192.168.1.11 netmask 255.255.255.0 up

# ifconfig  eth1
eth1      Link encap:Ethernet  HWaddr 24:3A:97:23:C9:01  
          inet addr:192.168.1.11  Bcast:192.168.1.255  Mask:255.255.255.0
          UP 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:1000 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

We can also change some interface settings as well through ifconfig command. Let see some examples of it.

Change MTU value of interface

MTU (Maximum Transmit Unit) is largest protocol data unit in bytes that can communicated through any interface in single network transaction, please don’t get confuse with frame size as it is transported on data link layer.
With below commands you could change MTU value

# ifconfig  eth0 | grep -i mtu
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

# ifconfig  eth0 mtu 2500

# ifconfig  eth0 | grep -i mtu
          UP BROADCAST RUNNING MULTICAST  MTU:2500  Metric:1

Enable Promiscuous Mode

Check ENACFIRE Wireless Headphones on special price

you could enable Promiscuous Mode of any interface through ifconfig command.
By-default NIC (Network interface controller) used to receive only packets belong to it(frame address is address to that NIC’s MAC address) or is broadcast/multicast address frame, all other packets are dropped through NIC.
But in promiscuous mode, NIC will every packet to CPU for processing regardless of it belong to it or not, this condition is used mainly for packet sniffing.
With below command we could enable promiscuous mode

# ifconfig eth0 | grep -i promi

# ifconfig eth0 promisc

# ifconfig eth0 | grep -i promi
          UP BROADCAST RUNNING PROMISC MULTICAST  MTU:2500  Metric:1

We can also remove promiscuous mode with below command

# ifconfig eth0 | grep -i promi

Add another alias to Interface

Sometime you need to add another IP address on same interface card, it could belongs to same network subnet or to different basis on its requirement.

# ifconfig eth0:1

eth0:1    Link encap:Ethernet  HWaddr 24:3A:97:23:C9:00  
          UP BROADCAST RUNNING MULTICAST  MTU:2500  Metric:1

# ifconfig  eth0:1 192.168.0.1 netmask 255.255.0.0 up

# ifconfig eth0:1
eth0:1    Link encap:Ethernet  HWaddr 24:3A:97:23:C9:00  
          inet addr:192.168.0.1  Bcast:192.168.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:2500  Metric:1

Don’t get confuse that how eth0:1 interface was appeared even when we didn’t assigned it on it, you can check as many alias on interface, we just need to use them with assign IP on it.

We can also make this configuration persistent, if we create interface file and save all details in it.

To remove these settings from eth0:1 interface, we just need to down this alias with below command.

# ifconfig  eth0:1 down

Change Interface Mac address

In case you like to change you interface mac address, you could do this with ifconfig command, but please be careful while doing it.

#  ifconfig eth0 | grep HWaddr
eth0      Link encap:Ethernet  HWaddr 24:3A:97:23:C9:00  

#  ifconfig eth0 hw ether 24:3A:97:23:C9:02

#  ifconfig eth0 | grep HWaddr
eth0      Link encap:Ethernet  HWaddr 24:3A:97:23:C9:02  

Interface Status Report

We can see interface reports through ifconfig command like below output show receive, transmit, error, drops etc for active interfaces.

# ifconfig  -s
Iface   MTU Met    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth1       1500   0 19855681      0      0      0 13773739      0      0      0 BMRU
lo        65536   0     7715      0      0      0     7715      0      0      0 LRU