Linux ifconfig command


The ifconfig command in Linux is used to configure, display, and manage network interfaces. While it is deprecated in favor of the ip command on modern systems, ifconfig is still widely used and available on many Linux distributions. Below is an explanation of the ifconfig command with commonly used options and examples of its output.

Basic Syntax of ifconfig

ifconfig [interface] [options]
  • interface: The name of the network interface (e.g., eth0, wlan0, lo).
  • options: Specific flags or arguments to modify or display certain network interface settings.

Common Options for ifconfig

1. Display Network Interfaces

  • To display all active network interfaces on your system:
    ifconfig
  • Example Output:
    eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.10 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::a00:27ff:fe4e:9a16 prefixlen 64 scopeid 0x20<link> ether 08:00:27:4e:9a:16 txqueuelen 1000 (Ethernet) RX packets 1000 bytes 1200000 (1.2 MB) TX packets 800 bytes 800000 (800 KB) lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 2000 bytes 1600000 (1.6 MB) TX packets 2000 bytes 1600000 (1.6 MB)
  • Explanation of fields:
    • flags: Indicates the status and features of the interface (e.g., UP, RUNNING, BROADCAST, etc.).
    • inet: The IPv4 address assigned to the interface.
    • netmask: The subnet mask.
    • broadcast: The broadcast address for the network.
    • ether: The MAC address of the network interface.
    • RX packets: Number of received packets.
    • TX packets: Number of transmitted packets.

2. Display Specific Interface Information

  • To display the information for a specific interface (e.g., eth0):
    ifconfig eth0
  • Example Output:
    eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.10 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::a00:27ff:fe4e:9a16 prefixlen 64 scopeid 0x20<link> ether 08:00:27:4e:9a:16 txqueuelen 1000 (Ethernet) RX packets 1000 bytes 1200000 (1.2 MB) TX packets 800 bytes 800000 (800 KB)

3. Enable/Disable an Interface

  • To enable or bring up a network interface (e.g., eth0):
    sudo ifconfig eth0 up
  • To disable or bring down a network interface:
    sudo ifconfig eth0 down

4. Assign an IP Address to an Interface

  • To assign a static IP address to a network interface (eth0 in this case):
    sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0 up
  • This assigns the IP 192.168.1.100 to eth0 and brings the interface up.

5. Change the MAC Address

  • To change the MAC address of an interface:
    sudo ifconfig eth0 hw ether 00:11:22:33:44:55
  • This changes the MAC address of eth0 to 00:11:22:33:44:55.

6. Set the MTU (Maximum Transmission Unit)

  • To change the MTU for an interface (e.g., eth0):
    sudo ifconfig eth0 mtu 1500
  • This sets the MTU of eth0 to 1500 bytes, which is typical for Ethernet connections.

7. View or Change Network Settings (Broadcast Address, IP, Netmask, etc.)

  • To change the broadcast address of an interface:
    sudo ifconfig eth0 broadcast 192.168.1.255
  • To change the netmask:
    sudo ifconfig eth0 netmask 255.255.255.128

8. View the ARP Cache

  • To view the ARP (Address Resolution Protocol) cache, which maps IP addresses to MAC addresses:
    ifconfig -a

9. Display Interface Statistics

  • To display additional statistics about network interfaces, including packet counts, errors, and collisions:
    ifconfig -s
  • Example Output:
    Interface MTU RX-OK RX-ERR RX-DROP TX-OK TX-ERR TX-DROP eth0 1500 120000 0 0 90000 0 0 lo 65536 200000 0 0 200000 0 0

10. Set a Network Interface to DHCP

  • To configure a network interface (eth0) to obtain an IP address automatically using DHCP:
    sudo ifconfig eth0 up sudo dhclient eth0

Example of Using ifconfig

Let’s go through an example where we configure a network interface.

1. Display the Current Network Interfaces

ifconfig
  • Output:
    eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.10 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::a00:27ff:fe4e:9a16 prefixlen 64 scopeid 0x20<link> ether 08:00:27:4e:9a:16 txqueuelen 1000 (Ethernet) RX packets 1000 bytes 1200000 (1.2 MB) TX packets 800 bytes 800000 (800 KB)

2. Assign a New IP Address

sudo ifconfig eth0 192.168.1.200 netmask 255.255.255.0 up
  • After executing the command, the eth0 interface will have the new IP address 192.168.1.200.

3. Verify the Change

ifconfig eth0
  • Output (new IP):
    eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.200 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::a00:27ff:fe4e:9a16 prefixlen 64 scopeid 0x20<link> ether 08:00:27:4e:9a:16 txqueuelen 1000 (Ethernet) RX packets 1000 bytes 1200000 (1.2 MB) TX packets 800 bytes 800000 (800 KB)

4. Disable the Interface

sudo ifconfig eth0 down

Summary of Common ifconfig Options:

OptionDescription
ifconfigDisplay all active interfaces
ifconfig [interface]Display details of a specific interface
ifconfig [interface] upEnable a specific network interface
ifconfig [interface] downDisable a specific network interface
ifconfig [interface] [IP]Assign a static IP address to an interface
ifconfig [interface] mtu [size]Set the Maximum Transmission Unit (MTU)
ifconfig -aShow all interfaces (including inactive ones)
ifconfig -sShow summary statistics for all interfaces

While ifconfig is widely used, remember that it is being replaced by the more powerful ip command on many modern Linux systems. However, ifconfig is still an important tool for understanding and managing basic network configurations.