The ifconfig command, short for “interface configuration,” is a powerful tool for managing network interfaces in Linux operating systems. Whether you’re assigning IP addresses, enabling or disabling interfaces, managing ARP cache, or configuring routes, ifconfig provides essential functionality for network administration.

Introduction to ifconfig

ifconfig is part of the legacy net-tools package, which has been widely used for configuring network interfaces. However, modern Linux distributions now favor the IP command, which offers more features and better support for IPv6. Despite its limitations, ifconfig remains a common choice for configuring network interfaces.

In this article, we’ll explore practical examples of using the ifconfig command. Before we dive into the examples, let’s cover some basics.

Prerequisites

Before you proceed, ensure you have the following:

  1. A Linux system.
  2. Access to the terminal.
  3. Sudo privileges (if you plan to modify network interface settings).

Basic Syntax

The basic syntax of the ifconfig command is as follows:

ifconfig [interface_name_optional] [arguments_optional]
  • When executed without arguments or with only the interface name, ifconfig prints essential information about all active network interfaces.
  • If used with arguments, it performs specific configuration tasks.

Common Options

Here are some common options for the ifconfig command:

  1. -a: Prints the configuration for all interfaces, including inactive ones.
  2. -s: Displays a shortlist of all interfaces.
  3. -v: Provides a more detailed configuration for all interfaces.
  4. interface_name: Represents the interface’s name (e.g., eth0, enp0s3) and is accompanied by a unit number.
  5. down: Deactivates the interface.
  6. up: Activates the interface.
  7. [IP_address_number]: Assigns an IP address to a specific interface.
  8. netmask [address]: Changes the network mask for an interface.
  9. broadcast [address]: Sets the broadcast address.
  10. mtu [number]: Sets the Maximum Transfer Unit (MTU) of an interface.
  11. promisc: Enables promiscuous mode (receives all packets).
  12. [-]promisc: Disables promiscuous mode.
  13. arp: Enables the ARP protocol.
  14. [-]arp: Disables the ARP protocol.
  15. allmulti: Enables all-multicast mode (receives all multicast packets).
  16. [-]allmulti: Disables all-multicast mode.

Practical Examples

Let’s explore some common use cases:

  1. View Active Network Interfaces:
    Run ifconfig with no arguments to display essential information about all active network interfaces. This includes interface names (e.g., enp0s3, lo). Note that sudo is not required for view operations.
  2. Assign an IP Address:
    Use ifconfig [interface_name] [IP_address] to assign an IP address to a specific interface.
  3. Change MTU:
    Set the MTU using ifconfig [interface_name] mtu [number].

Remember that while ifconfig is still in use, the IP command is the preferred alternative due to its enhanced capabilities and better support for modern networking requirements.

In summary, mastering ifconfig is essential for any Linux sysadmin or network engineer. Whether you’re troubleshooting connectivity issues or fine-tuning network settings, this command remains a valuable tool in your arsenal.


References:

  1. Linux ifconfig Command Explained With 19 Practical Examples
  2. Linuxize: ifconfig Command
  3. LinuxCapable: ifconfig Command in Linux with Practical Examples.